Send code verifier to backend

This commit is contained in:
MartinBraquet
2025-10-30 18:44:22 +01:00
parent 8a1b762c35
commit d42a5a48e9
3 changed files with 12 additions and 4 deletions

View File

@@ -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',
};

View File

@@ -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',

View File

@@ -81,7 +81,13 @@ function MyApp({Component, pageProps}: AppProps<PageProps>) {
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
}