working redirect and all hahahah hacky with two libraries but part of the game since I'm doing electron

This commit is contained in:
talksik
2022-05-28 09:59:11 -05:00
parent 0558df4f03
commit b2b47bedc4
2 changed files with 28 additions and 27 deletions
+1 -1
View File
@@ -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
+27 -26
View File
@@ -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<IAuthContext>({});
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 (