working redirect and all hahahah hacky with two libraries but part of the game since I'm doing electron
This commit is contained in:
@@ -7,7 +7,7 @@ const myApiOauth = new ElectronGoogleOAuth2(
|
|||||||
'423533244953-banligobgbof8hg89i6cr1l7u0p7c2pk.apps.googleusercontent.com',
|
'423533244953-banligobgbof8hg89i6cr1l7u0p7c2pk.apps.googleusercontent.com',
|
||||||
'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',
|
'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',
|
||||||
[''],
|
[''],
|
||||||
{ successRedirectURL: 'http://localhost:3000/auth/success' },
|
{ successRedirectURL: 'https://usenirvana.com' },
|
||||||
);
|
);
|
||||||
|
|
||||||
// FRESH GOOGLE LOGIN
|
// FRESH GOOGLE LOGIN
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { Credentials } from 'google-auth-library/build/src/auth/credentials';
|
||||||
import { Button, Container } from '@mui/material';
|
import { Button, Container } from '@mui/material';
|
||||||
import React, { useContext, useEffect, useCallback } from 'react';
|
import React, { useContext, useEffect, useCallback } from 'react';
|
||||||
|
|
||||||
@@ -5,7 +6,7 @@ import { FcGoogle } from 'react-icons/fc';
|
|||||||
import { blueGrey } from '@mui/material/colors';
|
import { blueGrey } from '@mui/material/colors';
|
||||||
import Channels from '../electron/constants';
|
import Channels from '../electron/constants';
|
||||||
import { firebaseAuth } from '../firebase/connect';
|
import { firebaseAuth } from '../firebase/connect';
|
||||||
import { GoogleAuthProvider, signInWithPopup } from 'firebase/auth';
|
import { GoogleAuthProvider, signInWithCredential } from 'firebase/auth';
|
||||||
|
|
||||||
const provider = new GoogleAuthProvider();
|
const provider = new GoogleAuthProvider();
|
||||||
|
|
||||||
@@ -19,10 +20,32 @@ const AuthContext = React.createContext<IAuthContext>({});
|
|||||||
|
|
||||||
export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
|
export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
|
||||||
useEffect(() => {
|
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);
|
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
|
// take user to browser to complete authentication
|
||||||
const handleLogin = useCallback(() => {
|
const handleLogin = useCallback(() => {
|
||||||
// send to main process
|
// send to main process
|
||||||
// window.electronAPI.auth.initiateLogin();
|
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);
|
|
||||||
// ...
|
|
||||||
});
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user