This commit is contained in:
MartinBraquet
2025-10-30 18:01:49 +01:00
parent e41bc64b0c
commit cae4b15bbb
8 changed files with 59 additions and 31 deletions

View File

@@ -0,0 +1,32 @@
import {APIHandler} from './helpers/endpoint'
import {GOOGLE_CLIENT_ID} from "common/constants";
export const authGoogle: APIHandler<'auth-google'> = async (
{code},
_auth
) => {
console.log('Google Auth Code:', code)
if (!code) return {success: false, result: {}}
const body = {
client_id: GOOGLE_CLIENT_ID,
client_secret: process.env.GOOGLE_CLIENT_SECRET!,
code: code as string,
grant_type: 'authorization_code',
redirect_uri: 'https://www.compassmeet.com/auth/callback',
};
console.log('Body:', body)
const tokenRes = await fetch('https://oauth2.googleapis.com/token', {
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
body: new URLSearchParams(body),
});
const tokens = await tokenRes.json();
console.log('Google Tokens:', tokens);
return {
success: true,
result: {tokens},
}
}