Share Access token to all controllers #2560
-
Hello, first of thank you for the great Hono framework! I'm trying to build a backend with hono and deno, and I have an issue with my access token. When my user logs in I want to create a bearer token that is used for authentication which is sent with every request to the backend. Therefore I want my routes to be protected with bearerAuth - somewhat like so: let token;
auth.post('/login', async (c) => {
...
token = accessToken.generate('gmd');
return c.json(token);
}
auth.get('/secret-data', bearerAuth({token: token}), (c) => {
return c.json('SECRET');
}); However I get the error that the token cannot be null or empty and when I set Maybe I'm approaching this all wrong, if you have an idea please let me know. Your help is much appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 9 replies
-
I see the |
Beta Was this translation helpful? Give feedback.
I would just use the middleware setup for JWT if you are using that, the Bearer Auth is more for API keys or a single key
https://hono.dev/middleware/builtin/jwt