@@ -78,42 +78,43 @@ export const auth0Client: FastifyPluginCallbackTypebox = fp(
78
78
} ) ;
79
79
80
80
// TODO: use a schema to validate the query params.
81
- fastify . get ( '/auth/auth0/callback' , async function ( request , reply ) {
82
- const { error, error_description } = request . query as Record <
83
- string ,
84
- string
85
- > ;
81
+ fastify . get ( '/auth/auth0/callback' , async function ( req , reply ) {
82
+ const logger = fastify . log . child ( { req } ) ;
83
+
84
+ const { error, error_description } = req . query as Record < string , string > ;
86
85
if ( error === 'access_denied' ) {
87
86
const blockedByLaw =
88
87
error_description === 'Access denied from your location' ;
89
-
90
88
if ( blockedByLaw ) {
89
+ logger . info ( 'Access denied due to user location' ) ;
91
90
return reply . redirect ( `${ HOME_LOCATION } /blocked` ) ;
92
91
} else {
92
+ logger . error ( 'Authentication failed for user:' + error_description ) ;
93
+
93
94
return reply . redirectWithMessage ( `${ HOME_LOCATION } /learn` , {
94
95
type : 'info' ,
95
96
content : error_description ?? 'Authentication failed'
96
97
} ) ;
97
98
}
98
99
}
99
100
100
- const { returnTo, pathPrefix, origin } = getLoginRedirectParams ( request ) ;
101
+ const { returnTo, pathPrefix, origin } = getLoginRedirectParams ( req ) ;
101
102
const redirectBase = getPrefixedLandingPath ( origin , pathPrefix ) ;
102
103
103
104
let token ;
104
105
try {
105
106
token = (
106
- await this . auth0OAuth . getAccessTokenFromAuthorizationCodeFlow ( request )
107
+ await this . auth0OAuth . getAccessTokenFromAuthorizationCodeFlow ( req )
107
108
) . token ;
108
109
} catch ( error ) {
109
110
// This is the plugin's error message. If it changes, we will either
110
111
// have to update the test or write custom state create/verify
111
112
// functions.
112
113
if ( error instanceof Error && error . message === 'Invalid state' ) {
113
- fastify . log . error ( 'Auth failed: invalid state' ) ;
114
+ logger . error ( 'Auth failed: invalid state' ) ;
114
115
} else {
115
- fastify . log . error ( 'Auth failed:' ) ;
116
- fastify . log . error ( error ) ;
116
+ logger . error ( 'Auth failed:' ) ;
117
+ logger . error ( error ) ;
117
118
fastify . Sentry . captureException ( error ) ;
118
119
}
119
120
// It's important _not_ to redirect to /signin here, as that could
@@ -132,7 +133,7 @@ export const auth0Client: FastifyPluginCallbackTypebox = fp(
132
133
email = userinfo . email ;
133
134
if ( typeof email !== 'string' ) throw Error ( 'Invalid userinfo response' ) ;
134
135
} catch ( error ) {
135
- fastify . log . error ( 'Auth failed' , error ) ;
136
+ logger . error ( { error } , 'Auth failed' ) ;
136
137
fastify . Sentry . captureException ( error ) ;
137
138
return reply . redirect ( '/signin' ) ;
138
139
}
0 commit comments