@@ -17,13 +17,19 @@ export async function authRoutes(app: FastifyInstance) {
1717
1818 app . get ( '/github' , async ( request : FastifyRequest , reply : FastifyReply ) => {
1919 const redirectUri = `${ process . env . BACKEND_URL } /auth/github/callback` ;
20+ const clientState = ( request . query as any ) . state || '' ;
21+ const state = clientState ? `${ clientState } _${ generateState ( ) } ` : generateState ( ) ;
22+
2023 const params = new URLSearchParams ( {
21- client_id : process . env . GITHUB_CLIENT_ID || '' ,
24+ client_id : ( process . env . GITHUB_CLIENT_ID || '' ) . trim ( ) ,
2225 redirect_uri : redirectUri ,
2326 scope : 'read:user user:email' ,
24- state : generateState ( ) ,
27+ state,
2528 } ) ;
26- return reply . redirect ( `${ GITHUB_AUTH_URL } ?${ params } ` ) ;
29+ const authUrl = `${ GITHUB_AUTH_URL } ?${ params } ` ;
30+ console . log ( '--- GITHUB OAUTH REDIRECT ---' ) ;
31+ console . log ( 'URL:' , authUrl ) ;
32+ return reply . redirect ( authUrl ) ;
2733 } ) ;
2834
2935 app . get ( '/github/callback' , async ( request : FastifyRequest < { Querystring : OAuthCallbackQuery } > , reply : FastifyReply ) => {
@@ -41,8 +47,8 @@ export async function authRoutes(app: FastifyInstance) {
4147 Accept : 'application/json' ,
4248 } ,
4349 body : JSON . stringify ( {
44- client_id : process . env . GITHUB_CLIENT_ID ,
45- client_secret : process . env . GITHUB_CLIENT_SECRET ,
50+ client_id : ( process . env . GITHUB_CLIENT_ID || '' ) . trim ( ) ,
51+ client_secret : ( process . env . GITHUB_CLIENT_SECRET || '' ) . trim ( ) ,
4652 code,
4753 redirect_uri : `${ process . env . BACKEND_URL } /auth/github/callback` ,
4854 } ) ,
@@ -128,15 +134,21 @@ export async function authRoutes(app: FastifyInstance) {
128134
129135 app . get ( '/google' , async ( request : FastifyRequest , reply : FastifyReply ) => {
130136 const redirectUri = `${ process . env . BACKEND_URL } /auth/google/callback` ;
137+ const clientState = ( request . query as any ) . state || '' ;
138+ const state = clientState ? `${ clientState } _${ generateState ( ) } ` : generateState ( ) ;
139+
131140 const params = new URLSearchParams ( {
132- client_id : process . env . GOOGLE_CLIENT_ID || '' ,
141+ client_id : ( process . env . GOOGLE_CLIENT_ID || '' ) . trim ( ) ,
133142 redirect_uri : redirectUri ,
134143 response_type : 'code' ,
135144 scope : 'openid email profile' ,
136- state : generateState ( ) ,
145+ state,
137146 access_type : 'offline' ,
138147 } ) ;
139- return reply . redirect ( `${ GOOGLE_AUTH_URL } ?${ params } ` ) ;
148+ const authUrl = `${ GOOGLE_AUTH_URL } ?${ params } ` ;
149+ console . log ( '--- GOOGLE OAUTH REDIRECT ---' ) ;
150+ console . log ( 'URL:' , authUrl ) ;
151+ return reply . redirect ( authUrl ) ;
140152 } ) ;
141153
142154 app . get ( '/google/callback' , async ( request : FastifyRequest < { Querystring : OAuthCallbackQuery } > , reply : FastifyReply ) => {
0 commit comments