@@ -6,6 +6,8 @@ import { ROUTES } from '../../shared/routes';
6
6
import { appContext } from '../applicationContext' ;
7
7
import { getPayloadUserId } from './jwt' ;
8
8
9
+ const WEBHOOKS_BASE_PATH = '/api/webhooks/' ;
10
+
9
11
// Middleware function
10
12
export function singleUserMiddleware ( req : FastifyRequest , _res : any , next : ( ) => void ) : void {
11
13
const user = appContext ( ) . userService . getSingleUser ( ) ;
@@ -17,7 +19,7 @@ export function singleUserMiddleware(req: FastifyRequest, _res: any, next: () =>
17
19
18
20
export function jwtAuthMiddleware ( req : FastifyRequest , reply : FastifyReply , done : ( ) => void ) : void {
19
21
// Skip auth for public endpoints
20
- if ( req . raw . url . startsWith ( '/webhooks/' ) || req . raw . url === DEFAULT_HEALTHCHECK || req . raw . url . startsWith ( ROUTES . AUTH_ROUTE_PREFIX ) ) {
22
+ if ( req . raw . url . startsWith ( WEBHOOKS_BASE_PATH ) || req . raw . url === DEFAULT_HEALTHCHECK || req . raw . url . startsWith ( ROUTES . AUTH_ROUTE_PREFIX ) ) {
21
23
done ( ) ;
22
24
return ;
23
25
}
@@ -51,12 +53,12 @@ export function jwtAuthMiddleware(req: FastifyRequest, reply: FastifyReply, done
51
53
52
54
export function googleIapMiddleware ( req : FastifyRequest , reply : FastifyReply , next : ( ) => void ) {
53
55
// It would be nicer if the health-check was earlier in the chain. Maybe when nextauthjs integration is done.
54
- if ( req . raw . url . startsWith ( '/webhooks/' ) || req . raw . url === DEFAULT_HEALTHCHECK ) {
56
+ if ( req . raw . url . startsWith ( WEBHOOKS_BASE_PATH ) || req . raw . url === DEFAULT_HEALTHCHECK ) {
55
57
next ( ) ;
56
58
return ;
57
59
}
58
60
let email = req . headers [ 'x-goog-authenticated-user-email' ] ;
59
- if ( ! email ) throw new Error ( ' x-goog-authenticated-user-email header not found' ) ;
61
+ if ( ! email ) throw new Error ( ` x-goog-authenticated-user-email header not found requesting ${ req . raw . url } ` ) ;
60
62
if ( Array . isArray ( email ) ) email = email [ 0 ] ;
61
63
// TODO validate the JWT https://cloud.google.com/iap/docs/signed-headers-howto#securing_iap_headers
62
64
0 commit comments