Overview
Neuron Meet uses JWT (JSON Web Tokens) for API authentication. After successful registration or login, you receive an access token that must be included in subsequent requests to protected endpoints.Token Structure
JWT tokens contain the following payload:Token Claims
sub- Subject: The unique user IDemail- User’s email addressiat- Issued At: When the token was createdexp- Expiration: When the token expires
Token Expiration
Access tokens are valid for 7 days from the time of issuance. After expiration, you must login again to obtain a new token.Using JWT Tokens
Authorization Header
Include the JWT token in theAuthorization header as a Bearer token:
Example: Get Current User Profile
Protected Endpoints
The following endpoints require JWT authentication:GET /auth/me- Get current user profilePOST /rooms- Create a new roomGET /rooms/:id- Get room details- All WebSocket connections for video conferencing
Authentication Flow
- Register or Login: Call
/auth/registeror/auth/loginto obtain an access token - Store Token: Save the
accessTokensecurely (e.g., localStorage, secure cookie) - Include in Requests: Add the token to the
Authorizationheader asBearer {token} - Handle Expiration: When receiving 401 errors, prompt user to login again
Token Validation
The server validates JWT tokens using theJWT_SECRET environment variable. The JWT strategy:
- Extracts the token from the
Authorizationheader - Verifies the token signature using the secret key
- Checks token expiration
- Validates the user still exists in the database
- Attaches user object to the request
Error Responses
401 Unauthorized
Returned when:- No token is provided
- Token is invalid or malformed
- Token signature verification fails
- Token has expired
- User associated with token no longer exists
Security Best Practices
- Never expose your
JWT_SECRETin client-side code - Store tokens securely (avoid localStorage in sensitive applications)
- Always use HTTPS in production to prevent token interception
- Implement token refresh mechanisms for long-lived sessions
- Clear tokens on logout