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

@@ -69,6 +69,7 @@ import {IS_LOCAL} from "common/envs/constants";
import {localSendTestEmail} from "api/test";
import path from "node:path";
import {saveSubscriptionMobile} from "api/save-subscription-mobile";
import {authGoogle} from "api/auth-google";
// const corsOptions: CorsOptions = {
// origin: ['*'], // Only allow requests from this domain
@@ -358,6 +359,7 @@ const handlers: { [k in APIPath]: APIHandler<k> } = {
'save-subscription-mobile': saveSubscriptionMobile,
'create-bookmarked-search': createBookmarkedSearch,
'delete-bookmarked-search': deleteBookmarkedSearch,
'auth-google': authGoogle,
}
Object.entries(handlers).forEach(([path, handler]) => {

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},
}
}