You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, my endpoints should respond differently to the request depending on which of the two strategies was used.
So, in my request handler, how can I know if fastify-auth authenticated the request with bearer auth or as anonymous?
awaitfastify.register(auth).register(bearerAuthPlugin,{addHook: false, keys,verifyErrorLogLevel: 'debug'}).decorate('allowAnonymous',function(req,reply,done){if(req.headers.authorization){returndone(Error('not anonymous'))}returndone()})fastify.route({method: 'GET',url: '/multiauth',preHandler: fastify.auth([fastify.allowAnonymous,fastify.verifyBearerAuth]),handler: function(req,reply){if(AUTHWASBEARER){// <--- How to make this check?reply.send({auth: 'bearer'})}else{reply.send({auth: 'anonymous'});}}})
Your Environment
node version: 23
fastify version: >=5.2.0
os: Linux
The text was updated successfully, but these errors were encountered:
💬 Question here
I use fastify-bearer-auth with fastify-auth to authenticate requests. I have a few endpoints where the bearer auth is optional. This pretty much follows this example perfectly: https://github.com/fastify/fastify-bearer-auth?tab=readme-ov-file#integration-with-fastifyauth
However, my endpoints should respond differently to the request depending on which of the two strategies was used.
So, in my request handler, how can I know if fastify-auth authenticated the request with bearer auth or as anonymous?
Your Environment
The text was updated successfully, but these errors were encountered: