@@ -702,16 +702,19 @@ const authPlugin: FastifyPluginAsync = async (fastify) => {
702702 fastify . decorateRequest ( 'supabase' , null )
703703 fastify . decorateRequest ( 'accessToken' , null )
704704
705+ // Store reference to logger for use in authenticate
706+ const log = fastify . log
707+
705708 fastify . decorate ( 'authenticate' , async function (
706709 request : FastifyRequest ,
707710 reply : FastifyReply
708711 ) : Promise < void > {
709- request . log . info ( '[Auth] authenticate() called ' )
712+ log . info ( '>>> [Auth] authenticate() ENTRY ' )
710713 const authHeader = request . headers . authorization
711- request . log . info ( { msg : '[Auth] Header check' , hasAuth : ! ! authHeader , authPrefix : authHeader ?. substring ( 0 , 20 ) } )
714+ log . info ( { msg : '>>> [Auth] Header check' , hasAuth : ! ! authHeader , authPrefix : authHeader ?. substring ( 0 , 20 ) } )
712715
713716 if ( ! authHeader || ! authHeader . startsWith ( 'Bearer ' ) ) {
714- request . log . warn ( '[Auth] Missing or invalid auth header' )
717+ log . warn ( '>>> [Auth] Missing or invalid auth header' )
715718 return reply . code ( 401 ) . send ( {
716719 error : 'Unauthorized' ,
717720 message : 'Missing or invalid Authorization header'
@@ -722,7 +725,7 @@ const authPlugin: FastifyPluginAsync = async (fastify) => {
722725
723726 // Check for literal "undefined" string (frontend bug protection)
724727 if ( ! token || token === 'undefined' || token === 'null' ) {
725- request . log . warn ( '[Auth] Empty or invalid token string' )
728+ log . warn ( '>>> [Auth] Empty or invalid token string' )
726729 return reply . code ( 401 ) . send ( {
727730 error : 'Unauthorized' ,
728731 message : 'Invalid or missing access token'
@@ -735,8 +738,8 @@ const authPlugin: FastifyPluginAsync = async (fastify) => {
735738
736739 if ( error || ! user ) {
737740 // Log detailed auth failure for debugging
738- request . log . error ( {
739- msg : '[Auth] Token verification failed' ,
741+ log . error ( {
742+ msg : '>>> [Auth] Token verification failed' ,
740743 error : error ?. message ,
741744 errorCode : error ?. code ,
742745 hasUser : ! ! user ,
@@ -756,15 +759,15 @@ const authPlugin: FastifyPluginAsync = async (fastify) => {
756759 . single ( )
757760
758761 if ( profileError || ! profile ) {
759- request . log . error ( { msg : '[Auth] Profile lookup failed' , error : profileError ?. message } )
762+ log . error ( { msg : '>>> [Auth] Profile lookup failed' , error : profileError ?. message } )
760763 return reply . code ( 401 ) . send ( {
761764 error : 'Profile not found' ,
762765 message : 'User profile does not exist'
763766 } )
764767 }
765768
766769 if ( ! profile . org_id ) {
767- request . log . warn ( { msg : '[Auth] User has no organization' , email : profile . email } )
770+ log . warn ( { msg : '>>> [Auth] User has no organization' , email : profile . email } )
768771 return reply . code ( 403 ) . send ( {
769772 error : 'No organization' ,
770773 message : 'User is not a member of any organization'
@@ -775,9 +778,9 @@ const authPlugin: FastifyPluginAsync = async (fastify) => {
775778 request . user = profile as UserProfile
776779 request . supabase = supabase
777780 request . accessToken = token
778- request . log . info ( { msg : '[Auth] Authenticated' , email : profile . email } )
781+ log . info ( { msg : '>>> [Auth] Authenticated' , email : profile . email } )
779782 } catch ( err ) {
780- request . log . error ( { msg : '[Auth] Unexpected error' , error : err } )
783+ log . error ( { msg : '>>> [Auth] Unexpected error' , error : err } )
781784 return reply . code ( 500 ) . send ( {
782785 error : 'Auth error' ,
783786 message : err instanceof Error ? err . message : 'Unknown error'
0 commit comments