trying stuff and setting up auto

This commit is contained in:
talksik
2022-05-28 03:08:25 -05:00
parent 2def3fde91
commit c21c80b8f7
6 changed files with 216 additions and 4 deletions
@@ -1,5 +1,11 @@
import React, { useContext } from 'react';
import { Button, Container } from '@mui/material';
import React, { useContext, useEffect, useCallback } from 'react';
import Realm from 'realm';
import realmApp from '../realm/connect';
import { FcGoogle } from 'react-icons/fc';
import { blueGrey } from '@mui/material/colors';
import Channels from '../electron/constants';
interface IAuthContext {
user?: Realm.User;
@@ -8,9 +14,44 @@ interface IAuthContext {
const AuthContext = React.createContext<IAuthContext>({});
export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
useEffect(() => {
window.electronAPI.once(Channels.GOOGLE_AUTH_TOKENS, async (tokens: any) => {
console.log('got tokens', tokens);
// const credentials = Realm.Credentials.google(tokens);
// realmApp.logIn(credentials).then((user) => alert(`Logged in with id: ${user.id}`));
});
}, []);
return <Login />;
return <AuthContext.Provider value={{}}>{children}</AuthContext.Provider>;
};
const Login = () => {
// take user to browser to complete authentication
const handleLogin = useCallback(() => {
// send to main process
window.electronAPI.auth.initiateLogin();
}, []);
return (
<Container
maxWidth={false}
sx={{
display: 'flex',
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
background: blueGrey[50],
}}
>
<Button onClick={handleLogin} variant="outlined" color="primary" startIcon={<FcGoogle />}>
Continue with Google
</Button>
</Container>
);
};
const useAuth = () => {
return useContext(AuthContext);
};