@@ -19,6 +19,12 @@ const plugin: FastifyPluginCallback = (fastify, _options, done) => {
1919 'send401IfNoUser' ,
2020 async function ( req : FastifyRequest , reply : FastifyReply ) {
2121 if ( ! req . user ) {
22+ const logger = fastify . log . child ( { req } ) ;
23+
24+ logger . debug (
25+ 'User tried to access a protected route without being authenticated.'
26+ ) ;
27+
2228 await reply . status ( 401 ) . send ( {
2329 type : req . accessDeniedMessage ?. type ,
2430 message : req . accessDeniedMessage ?. content
@@ -30,7 +36,11 @@ const plugin: FastifyPluginCallback = (fastify, _options, done) => {
3036 fastify . decorate (
3137 'redirectIfNoUser' ,
3238 async function ( req : FastifyRequest , reply : FastifyReply ) {
39+ const logger = fastify . log . child ( { req } ) ;
3340 if ( ! req . user ) {
41+ logger . debug (
42+ 'User tried to access a protected route without being authenticated.'
43+ ) ;
3444 const { origin } = getRedirectParams ( req ) ;
3545 await reply . redirectWithMessage ( origin , {
3646 type : 'info' ,
@@ -45,7 +55,12 @@ const plugin: FastifyPluginCallback = (fastify, _options, done) => {
4555 'redirectIfSignedIn' ,
4656 async function ( req : FastifyRequest , reply : FastifyReply ) {
4757 if ( req . user ) {
58+ const logger = fastify . log . child ( { req } ) ;
59+
4860 const { returnTo } = getRedirectParams ( req ) ;
61+
62+ logger . debug ( `User is being redirected to: ${ returnTo } ` ) ;
63+
4964 await reply . redirect ( returnTo ) ;
5065 }
5166 }
0 commit comments