diff --git a/packages/desktop/src/electron/handleLogin.ts b/packages/desktop/src/electron/handleLogin.ts index b725381..89ccb9e 100644 --- a/packages/desktop/src/electron/handleLogin.ts +++ b/packages/desktop/src/electron/handleLogin.ts @@ -7,7 +7,7 @@ const myApiOauth = new ElectronGoogleOAuth2( '423533244953-banligobgbof8hg89i6cr1l7u0p7c2pk.apps.googleusercontent.com', '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', [''], - { successRedirectURL: 'http://localhost:3000/auth/success' }, + { successRedirectURL: 'https://usenirvana.com' }, ); // FRESH GOOGLE LOGIN diff --git a/packages/desktop/src/providers/AuthProvider.tsx b/packages/desktop/src/providers/AuthProvider.tsx index 21a443e..c47316b 100644 --- a/packages/desktop/src/providers/AuthProvider.tsx +++ b/packages/desktop/src/providers/AuthProvider.tsx @@ -1,3 +1,4 @@ +import { Credentials } from 'google-auth-library/build/src/auth/credentials'; import { Button, Container } from '@mui/material'; import React, { useContext, useEffect, useCallback } from 'react'; @@ -5,7 +6,7 @@ import { FcGoogle } from 'react-icons/fc'; import { blueGrey } from '@mui/material/colors'; import Channels from '../electron/constants'; import { firebaseAuth } from '../firebase/connect'; -import { GoogleAuthProvider, signInWithPopup } from 'firebase/auth'; +import { GoogleAuthProvider, signInWithCredential } from 'firebase/auth'; const provider = new GoogleAuthProvider(); @@ -19,10 +20,32 @@ const AuthContext = React.createContext({}); export const AuthProvider = ({ children }: { children: React.ReactNode }) => { useEffect(() => { - window.electronAPI.once(Channels.GOOGLE_AUTH_TOKENS, async (tokens: any) => { + window.electronAPI.once(Channels.GOOGLE_AUTH_TOKENS, async (tokens: Credentials) => { console.log('got tokens', tokens); - // realmApp.logIn(credentials).then((user) => alert(`Logged in with id: ${user.id}`)); + const credential = GoogleAuthProvider.credential(tokens.id_token); + + // Sign in with credential from the Google user. + signInWithCredential(firebaseAuth, credential) + .then((result) => { + // This gives you a Google Access Token. You can use it to access Google APIs. + const credential = GoogleAuthProvider.credentialFromResult(result); + const token = credential.accessToken; + + // The signed-in user info. + const user = result.user; + console.log(user); + }) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The credential that was used. + const credential = GoogleAuthProvider.credentialFromError(error); + // ... + }); }); }, []); @@ -35,29 +58,7 @@ const Login = () => { // take user to browser to complete authentication const handleLogin = useCallback(() => { // send to main process - // window.electronAPI.auth.initiateLogin(); - - signInWithPopup(firebaseAuth, provider) - .then((result) => { - // This gives you a Google Access Token. You can use it to access the Google API. - const credential = GoogleAuthProvider.credentialFromResult(result); - const token = credential.accessToken; - // The signed-in user info. - const user = result.user; - - console.log(result); - // ... - }) - .catch((error) => { - // Handle Errors here. - const errorCode = error.code; - const errorMessage = error.message; - // The email of the user's account used. - const email = error.customData.email; - // The AuthCredential type that was used. - const credential = GoogleAuthProvider.credentialFromError(error); - // ... - }); + window.electronAPI.auth.initiateLogin(); }, []); return (