Overview
Polaris IDE uses Stack Auth for authentication, providing a complete auth solution with pre-built UI components, OAuth integrations, and machine-to-machine (M2M) authentication for the desktop app.Polaris IDE migrated from Clerk to Stack Auth for better Convex integration and first-class Electron support.
Features
Pre-built UI
Beautiful, customizable sign-in and sign-up pages with no code required
OAuth Providers
GitHub, Google, and other OAuth providers supported out of the box
Convex Integration
Seamless JWT authentication with Convex real-time database
M2M Authentication
Machine-to-machine auth for Electron desktop app
Session Management
Secure cookie-based sessions with automatic refresh
User Management
Built-in user profiles and account settings
Setup
Create Stack Auth Project
Sign up for Stack Auth
Go to https://app.stack-auth.com and create an account.
Create a New Project
Click “New Project” and enter your project details:
- Project Name: Polaris IDE
- Environment: Development (create production later)
Copy Credentials
From the project dashboard, copy:
- Project ID
- Publishable Client Key
- Secret Server Key
Environment Variables
Add Stack Auth credentials to.env.local:
Client-Side Setup
Stack Auth client configuration (stack/client.ts:8):
Provider Setup
Wrap your app with the Stack provider (src/components/providers.tsx):
Get Current User
Access the authenticated user in client components:Server-Side Setup
Stack Auth server configuration (stack/server.ts:4):
API Route Authentication
Protect API routes using therequireAuth helper (src/lib/stack-auth-api.ts):
Get User in Server Components
Access the current user in server components:Authentication Flow
Sign In
Stack Auth provides a pre-built sign-in page at/handler/sign-in:
- Email/password sign-in form
- OAuth provider buttons (if configured)
- “Forgot password” link
- “Sign up” link
Sign Up
Similarly,/handler/sign-up provides a registration form:
- Email/password registration
- OAuth provider buttons
- Email verification (if enabled)
- Automatic redirect after signup
Account Settings
Users can manage their account at/handler/account-settings:
- Update profile information
- Change password
- Manage connected OAuth accounts
- Delete account
Convex Integration
Stack Auth integrates seamlessly with Convex for real-time database access.Convex Auth Configuration
Configure Convex to accept Stack Auth JWTs (convex/auth.config.ts:3):
Client-Side Convex Setup
Provide Convex authentication using Stack tokens:Verify Authentication in Convex
Validate users in Convex queries and mutations (convex/auth.ts):
User Management
User Schema
Convex user records (convex/schema.ts:8):
Create or Get User
Automatically create user records on first sign-in (convex/users.ts:19):
Desktop App Authentication (M2M)
The Electron desktop app uses machine-to-machine (M2M) authentication for server-side operations.M2M Token Generation
Generate M2M tokens using the Stack Auth API (src/lib/electron/stack-auth.ts):
Token Storage
Tokens are stored securely usingelectron-store:
Token Refresh
Automatically refresh expired tokens:Migration from Clerk
Polaris IDE previously used Clerk for authentication. The migration to Stack Auth is documented inSTACK_AUTH_MIGRATION_SUMMARY.md.
Key Changes
- Provider
- API Auth
- User ID
Before (Clerk):After (Stack Auth):
Backward Compatibility
The schema includes bothstackUserId and clerkId fields during the migration period:
Security Features
Cookie-based Sessions
Cookie-based Sessions
JWT Verification
JWT Verification
All JWTs are verified server-side before granting access:
- Signature validation
- Expiration checking
- Issuer verification
Rate Limiting
Rate Limiting
Stack Auth implements rate limiting on:
- Sign-in attempts
- Password reset requests
- Email verification sends
CSRF Protection
CSRF Protection
Cross-site request forgery protection is built-in:
- CSRF tokens for state-changing operations
- Origin validation
Troubleshooting
Environment Variables Missing
Environment Variables Missing
Issue: Console error about missing Stack Auth environment variablesSolution:
- Ensure
.env.localexists with all required variables - Restart the development server after adding variables
- Check variable names match exactly (including
NEXT_PUBLIC_prefix)
Unauthenticated Error in Convex
Unauthenticated Error in Convex
Issue: Convex queries/mutations fail with “Unauthenticated”Solution:
- Verify
convex/auth.config.tsis correctly configured - Check Convex client has auth set:
convex.setAuth(...) - Ensure user is signed in (check with
useUser()hook) - Verify Stack Auth project ID matches in all configs
Redirect Loop
Redirect Loop
Issue: Infinite redirect between sign-in page and protected routesSolution:
- Check that authentication URLs are correct in Stack config
- Verify middleware is not blocking auth handler routes
- Clear browser cookies and try again
Desktop App Auth Fails
Desktop App Auth Fails
Issue: Electron app cannot authenticate with ConvexSolution:
- Verify
STACK_SECRET_SERVER_KEYis set - Check M2M token generation is working
- Ensure electron-store can write to disk
- Check logs in
~/Library/Logs/Polaris IDE/(macOS)
Next Steps
Convex Integration
Learn how Convex stores and syncs data
GitHub Integration
Import and export projects to GitHub