User Profiles
UserButton Component
AiVault uses Clerk’sUserButton component to provide a dropdown menu for user account management:
components/layout/Navbar.tsx
- Profile picture display
- Account settings access
- Sign out functionality
- Customizable redirect after sign out
Mobile Navigation
For mobile devices, the user profile is displayed with additional context:showName prop displays the user’s name alongside their avatar.
Accessing User Information
Using useAuth Hook
TheuseAuth hook provides access to the current user’s authentication state:
userId- Unique identifier for the userisLoaded- Whether auth state has loadedisSignedIn- Whether user is authenticatedsessionId- Current session identifier
Using useConvexAuth Hook
For Convex-specific authentication state:app/dashboard/page.tsx
Session Management
Automatic Session Handling
Clerk automatically manages user sessions:- Sessions are created upon successful sign-in
- Tokens are automatically refreshed
- Sessions persist across page reloads
- Sessions are synchronized across tabs
Protected Route Access
When users access protected routes, AiVault checks their authentication status:app/dashboard/page.tsx
Session Expiration
Clerk handles session expiration automatically:- User session expires after inactivity
- User is redirected to sign-in page
- After sign-in, user returns to original page
User Dashboard
AiVault provides a personalized dashboard for authenticated users:Bookmarked Tools
Users can view their saved AI tools:- Display all bookmarked tools
- Quick access to tool details
- Remove bookmarks
- Empty state with call-to-action
Submitted Tools
Users can track their tool submissions:- Pending Review - Awaiting admin approval
- Approved - Live in the directory
Account Settings
Clerk Account Settings
Users can access their Clerk account settings through theUserButton dropdown:
- Profile - Update name, avatar, and bio
- Security - Change password, enable 2FA
- Connected Accounts - Manage OAuth connections
- Delete Account - Permanently remove account
Email Preferences
AiVault provides a dedicated settings page at/settings for managing email notification preferences. Users can customize:
- Submission confirmations - Get notified when you submit a new tool
- Approval/rejection updates - Receive updates on tool review status
- Marketing and product updates - Opt-in for AiVault news and features
unsafeMetadata for the user:
app/settings/page.tsx
Email preferences are saved to your user profile and persist across sessions.
Sign Out
Sign Out Flow
Users can sign out from multiple locations in AiVault:- Click the
UserButtonin the navigation bar - Select “Sign out” from the dropdown
- User is redirected to the home page
afterSignOutUrl prop ensures users are redirected to the homepage after signing out.
Post-Logout State
After logout:- Session is terminated
- User is redirected to specified URL
- Protected routes become inaccessible
- UI updates to show sign-in button
Role-Based Access
Admin Users
AiVault supports admin roles for managing tool submissions:Admin Configuration
Admin users are configured via environment variable:.env.local
- Sign in to your application
- Open browser DevTools
- Check the
userIdfromuseAuth()hook - Add the ID to the environment variable
Loading States
AiVault handles various loading states during authentication:Best Practices
Always check isLoaded before rendering
Always check isLoaded before rendering
Wait for
isLoaded from useAuth() to be true before checking userId or isSignedIn. This prevents flash of incorrect content.Use skip parameter for Convex queries
Use skip parameter for Convex queries
Skip Convex queries when user is not authenticated to avoid unnecessary requests:
Provide clear sign-in prompts
Provide clear sign-in prompts
When users aren’t authenticated, show clear messaging about why sign-in is required:
Next Steps
Authentication Setup
Learn how to set up Clerk authentication
Convex Backend
Make authenticated queries to Convex