Overview
Polaris uses Clerk for authentication with GitHub OAuth support. This guide walks you through setting up Clerk and integrating it with Convex for secure, real-time user authentication.Prerequisites
- A Clerk account (sign up here)
- A Convex deployment (see Database Setup)
Setup Steps
Create a Clerk Application
- Go to the Clerk Dashboard
- Click Add Application
- Name your application (e.g., “Polaris”)
- Select GitHub as your social login provider
- Click Create Application
Set Up Clerk Provider
Polaris wraps the application with This setup provides three authentication states:
ClerkProvider and integrates it with Convex using ConvexProviderWithClerk:src/components/providers.tsx
- Authenticated: User is signed in, show main app
- Unauthenticated: User is not signed in, show login page
- AuthLoading: Authentication status is being checked
Authentication Flow
User Identity
Once authenticated, Convex queries and mutations can access the user’s identity:convex/auth.ts
convex/projects.ts
Protected Routes
All routes are protected by default through theProviders component. Users must sign in with GitHub before accessing any part of the application.
Testing Authentication
Environment Variables Reference
Your Clerk publishable key (starts with
pk_test_ or pk_live_)Your Clerk secret key (starts with
sk_test_ or sk_live_)Your Clerk JWT issuer domain (set in Convex, not .env.local)
Troubleshooting
”Unauthorized” Error
If you see unauthorized errors in Convex functions:-
Verify
CLERK_JWT_ISSUER_DOMAINis set correctly in Convex: - Check that your Clerk keys are valid and match your environment (test vs. production)
- Ensure the Clerk application has GitHub OAuth enabled
Redirect Loop
If you experience a redirect loop:- Clear your browser cookies for
localhost - Verify your Clerk domain settings in the dashboard
- Check that
NEXT_PUBLIC_CONVEX_URLis set correctly
Next Steps
- Database Setup - Configure Convex database
- Environment Variables - Complete .env reference