mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-03-03 06:16:21 -05:00
Fix
This commit is contained in:
@@ -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]) => {
|
||||
|
||||
32
backend/api/src/auth-google.ts
Normal file
32
backend/api/src/auth-google.ts
Normal 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},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user