diff --git a/backend/api/src/auth-google.ts b/backend/api/src/auth-google.ts index c13831d7..d22754e9 100644 --- a/backend/api/src/auth-google.ts +++ b/backend/api/src/auth-google.ts @@ -2,16 +2,17 @@ import {APIHandler} from './helpers/endpoint' import {GOOGLE_CLIENT_ID} from "common/constants"; export const authGoogle: APIHandler<'auth-google'> = async ( - {code}, + {code, codeVerifier}, _auth ) => { - console.log('Google Auth Code:', code) - if (!code) return {success: false, result: {}} + console.log('Google Auth Codes:', code, codeVerifier) + if (!code || !codeVerifier) return {success: false, result: {}} const body = { client_id: GOOGLE_CLIENT_ID, client_secret: process.env.GOOGLE_CLIENT_SECRET!, code: code as string, + code_verifier: codeVerifier as string, grant_type: 'authorization_code', redirect_uri: 'https://www.compassmeet.com/auth/callback', }; diff --git a/common/src/api/schema.ts b/common/src/api/schema.ts index 56ee573c..46d534e1 100644 --- a/common/src/api/schema.ts +++ b/common/src/api/schema.ts @@ -740,6 +740,7 @@ export const API = (_apiTypeCheck = { returns: {} as any, props: z.object({ code: z.string(), + codeVerifier: z.string(), }), summary: 'Google Auth', tag: 'Authentication', diff --git a/web/pages/_app.tsx b/web/pages/_app.tsx index c44d0374..81e14b70 100644 --- a/web/pages/_app.tsx +++ b/web/pages/_app.tsx @@ -81,7 +81,13 @@ function MyApp({Component, pageProps}: AppProps) { return; } - const {result} = await unauthedApi('auth-google', {code}) + const codeVerifier = localStorage.getItem('pkce_verifier'); + if (!codeVerifier) { + console.error('No code verifier found in localStorage'); + return; + } + + const {result} = await unauthedApi('auth-google', {code, codeVerifier}) console.log('/auth-google result', result); // google sign in }