Overview
Polaris IDE uses Stack Auth for authentication. All API requests must include a valid JWT token in theAuthorization header.
Authentication Flow
- User signs in via Stack Auth (frontend)
- Stack Auth issues a JWT access token
- Frontend includes token in API requests
- Backend validates token and extracts user identity
Getting Your Access Token
From the Frontend
If you’re building a frontend application, use the Stack Auth SDK:JavaScript
For Testing (Development Only)
During development, you can obtain a token from the browser:- Open your Polaris IDE instance
- Open browser DevTools (F12)
- Run in console:
Making Authenticated Requests
Include the JWT token in theAuthorization header:
cURL
Fetch API
Python
Authentication Errors
401 Unauthorized
Returned when the token is missing, invalid, or expired:- Missing
Authorizationheader - Invalid or expired JWT token
- Token not properly formatted (should be
Bearer TOKEN)
- Ensure the token is included in the header
- Obtain a fresh token from Stack Auth
- Check token format
403 Forbidden
Returned when authenticated but lacking permissions:Environment Configuration
For self-hosted instances, configure Stack Auth in your environment:.env
Backend Implementation
If you’re building integrations or want to understand how authentication works internally:requireAuth() Helper
All API routes use therequireAuth() helper from src/lib/stack-auth-api.ts:
Token Validation
Stack Auth validates tokens automatically. TherequireAuth() function:
- Extracts the JWT from the
Authorizationheader - Validates the token signature and expiration
- Returns user object with ID and metadata
- Returns 401 error response if invalid
Security Best Practices
Use HTTPS in Production
Use HTTPS in Production
Always use HTTPS to prevent token interception. Never send tokens over unencrypted HTTP connections.
Never Commit Tokens
Never Commit Tokens
Never hardcode or commit tokens to version control. Use environment variables and secure secret management.
Rotate Tokens Regularly
Rotate Tokens Regularly
JWT tokens have expiration times. Implement token refresh logic in your application.
Validate on Every Request
Validate on Every Request
Always validate tokens server-side. Never trust client-side validation alone.
Migration from Clerk
Polaris IDE was migrated from Clerk to Stack Auth. If you’re maintaining an older version, update to use Stack Auth for better integration.
clerkId for backward compatibility during migration:
Next Steps
Projects API
Start creating projects
Messages API
Send AI conversation messages