Overview
GitFolio uses Clerk for authentication. All authenticated endpoints require a valid JWT token in theAuthorization header.
Authentication Flow
- User signs in through the GitFolio frontend using Clerk
- Clerk issues a JWT token to the client
- Client includes the token in API requests
- Server validates the token using Clerk’s backend SDK
Making Authenticated Requests
Include the JWT token in theAuthorization header with the Bearer scheme:
Authentication Middleware
The following endpoints require authentication:- All
/api/v1/dashboardendpoints - All
/api/v1/s3endpoints - All
/api/v1/onboardingendpoints - All
/api/v1/razorpayendpoints
Token Validation
The server validates tokens using:- Clerk Secret Key - Validates the token signature
- Clerk JWT Key - Verifies token claims
- User Lookup - Fetches user details from Clerk
Request Context
After successful authentication, the user context is attached to the request:Error Responses
Missing Token
Status: 401 UnauthorizedInvalid Token
Status: 401 UnauthorizedServer Error
Status: 500 Internal Server ErrorSign-in Methods
GitFolio supports three authentication methods through Clerk:The authentication method used during sign-in
GITHUB- Sign in with GitHub OAuthGOOGLE- Sign in with Google OAuthEMAIL- Sign in with email/password
authType is stored in the user’s profile and used during onboarding.
User ID
TheuserId from Clerk is used as the primary identifier throughout the GitFolio database. It’s a string value that uniquely identifies each user.
Security Best Practices
Never expose tokens
Never expose tokens
- Never commit tokens to version control
- Don’t log tokens in production
- Use environment variables for sensitive keys
Token rotation
Token rotation
- Tokens have expiration times set by Clerk
- Implement token refresh logic in your client
- Handle 401 errors by refreshing tokens
HTTPS only
HTTPS only
- Always use HTTPS in production
- Tokens sent over HTTP can be intercepted
- The API enforces HTTPS in production
Example: Getting User Data
Public Endpoints
These endpoints do NOT require authentication:GET /api/v1/renderer/:username- Public portfolio viewGET /api/v1/renderer/image/:username- Portfolio image dataGET /api/health- API health check