@@ -15,19 +15,23 @@ export const createCallbackEndpoint = (
15
15
// Support both GET (default OAuth2) and POST (required for Apple OAuth with form_post)
16
16
// - GET: Used by most OAuth providers (Google, GitHub, etc.)
17
17
// - POST: Required by Apple when requesting name/email scopes with response_mode=form_post
18
- method : [ 'get' , ' post'] ,
18
+ method : ' post' as const ,
19
19
path : pluginOptions . callbackPath || '/oauth/callback' ,
20
20
handler : async ( req ) => {
21
21
try {
22
- // Handle authorization code from both GET query params and POST body
23
- // This enables support for Apple's form_post response mode while maintaining
24
- // compatibility with traditional OAuth2 GET responses
25
- const code = req . method === 'POST' ? req . body ?. code : req . query ?. code
22
+ // Handle authorization code from both GET query params and POST body
23
+ // This enables support for Apple's form_post response mode while maintaining
24
+ // compatibility with traditional OAuth2 GET responses
25
+ const code = req . method === "POST"
26
+ ? ( req . body ) ?. code // Type assertion for body
27
+ : ( req . query ) ?. code // Type assertion for query
26
28
// Improved error handling to clearly indicate whether we're missing the code
27
29
// from POST body (Apple OAuth) or GET query parameters (standard OAuth)
28
30
if ( typeof code !== 'string' )
29
31
throw new Error (
30
- `Code not found in ${ req . method === 'POST' ? 'body' : 'query' } : ${ JSON . stringify ( req . method === 'POST' ? req . body : req . query ) } ` ,
32
+ `Code not found in ${ req . method === 'POST' ? 'body' : 'query' } : ${ JSON . stringify (
33
+ req . method === 'POST' ? req . body : req . query
34
+ ) } `,
31
35
)
32
36
33
37
// /////////////////////////////////////
0 commit comments