the token is not jwt really
it is a custom implementation that cannot be decoded on client side nut sufficient enough for server to auth users
to get the user info make api call to /api/user/me to get info like this
{
"status": "success",
"user": {
"id": "125b4768-0d58-4eb2-bb88-fb1be5544d80",
"username": "erina@gmail.com",
"email": "erina@gmail.com",
"name": "Erina",
"roles": [
"USER"
]
}
}
then use that to determine roles
also upon login save the token on server side then save cookies that help to identify which user has which token on server side
I understand now. Let me adjust our approach to work with your custom token implementation:
Thank you for the clarification. I've updated the authentication approach to work with your custom token implementation. Here's what I've changed:
Middleware:
auth_token cookie instead of trying to decode a JWTuser_role cookie to determine user roles for route protectionServer Components:
cookies() APIAuth Utilities:
/api/user/me endpointAPI Service:
credentials: "include" to ensure cookies are sent with requestsgetCurrentUser function to fetch user info from the APILogin Process:
This approach aligns with your authentication system where:
For a complete implementation, your backend would need to:
auth_token cookie during loginuser_role cookie with the user's role/api/user/me endpoint to return user informationThis setup provides a secure authentication flow where sensitive token information remains on the server while still allowing proper authorization checks throughout your application.
I understand now - thanks for the clarification. The API server is completely stateless and uses bearer token authentication, while the "server" you mentioned is actually the Next.js frontend environment.
Let me correct my approach:
Thank you for the clarification. I've updated the authentication approach to work with your stateless API server that uses bearer token authentication:
Token Storage:
API Authentication:
User Information:
/api/user/me endpoint using the stored tokenMiddleware:
Client-Side Auth Checks:
This approach works with your stateless API server while still providing proper authentication and authorization throughout your application. The token is stored client-side but used for all API requests, and user information including roles is fetched from the API when needed.