Skip to content

Commit

Permalink
Remove unwanted files
Browse files Browse the repository at this point in the history
  • Loading branch information
wryonik committed May 25, 2024
1 parent db6a076 commit 6f24ad3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 271 deletions.
30 changes: 0 additions & 30 deletions packages/app/src/contexts/Account/AccountContext.ts

This file was deleted.

172 changes: 0 additions & 172 deletions packages/app/src/contexts/Account/AccountProvider.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions packages/app/src/contexts/Account/index.ts

This file was deleted.

92 changes: 33 additions & 59 deletions packages/app/src/contexts/GoogleAuth/GoogleAuthProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import React, { useEffect, useState, ReactNode } from 'react'
import React, { useEffect, useState, ReactNode } from "react";
import {
hasGrantedAllScopesGoogle,
useGoogleLogin,
googleLogout,
} from '@react-oauth/google';
} from "@react-oauth/google";

// import GoogleAuthContext from './GoogleAuthContext'
import { fetchProfile } from '../../hooks/useGmailClient';
import useAccount from '../../hooks/useAccount';
import { esl } from '../../constants';
import GoogleAuthContext from './GoogleAuthContext';

import { fetchProfile } from "../../hooks/useGmailClient";
import useAccount from "../../hooks/useAccount";
import { esl } from "../../constants";
import GoogleAuthContext from "./GoogleAuthContext";

interface ProvidersProps {
children: ReactNode;
Expand All @@ -21,72 +20,44 @@ const GoogleAuthProvider = ({ children }: ProvidersProps) => {
* Contexts
*/

const { loggedInEthereumAddress } = useAccount()

/*
* State Keys
*/

const getGoogleAuthTokenKey = () => {
return `googleAuthToken_${loggedInEthereumAddress}`;
}

/*
* State
*/

const [googleAuthToken, setGoogleAuthToken] = useState<any | null>(
() => {
const cachedToken = localStorage.getItem(getGoogleAuthTokenKey());
return cachedToken ? JSON.parse(cachedToken) : null;
}
);
const [googleAuthToken, setGoogleAuthToken] = useState<any | null>();

const [isGoogleAuthed, setIsGoogleAuthed] = useState<boolean>(false);
const [isScopesApproved, setIsScopesApproved] = useState<boolean>(false);
const [loggedInGmail, setLoggedInGmail] = useState<string | null>(null);

/*
* Hooks
*/

useEffect(() => {
esl && console.log('logoOutGoogleAuth');
esl && console.log('checking loggedInEthereumAddress', loggedInEthereumAddress);

if (!loggedInEthereumAddress) {
esl && console.log('logoOutGoogleAuth_1');

googleLogOut();
}

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [loggedInEthereumAddress]);

useEffect(() => {
esl && console.log('googleAuthScopes_1');
esl && console.log('checking googleAuthToken', googleAuthToken);
esl && console.log("googleAuthScopes_1");
esl && console.log("checking googleAuthToken", googleAuthToken);

if (googleAuthToken) {
esl && console.log('googleAuthScopes_2');
esl && console.log("googleAuthScopes_2");

const allScope = hasGrantedAllScopesGoogle(
googleAuthToken,
'email',
'profile',
'https://www.googleapis.com/auth/gmail.readonly',
"email",
"profile",
"https://www.googleapis.com/auth/gmail.readonly"
);

setIsScopesApproved(allScope);
}
}, [googleAuthToken]);

useEffect(() => {
esl && console.log('googleProfile_1');
esl && console.log('checking googleAuthToken', googleAuthToken);
esl && console.log("googleProfile_1");
esl && console.log("checking googleAuthToken", googleAuthToken);

if (googleAuthToken) {
esl && console.log('googleProfile_2');
esl && console.log("googleProfile_2");

const fetchData = async () => {
try {
Expand All @@ -95,43 +66,46 @@ const GoogleAuthProvider = ({ children }: ProvidersProps) => {
if (email) {
setLoggedInGmail(email);

localStorage.setItem('loggedInEmail', email);
localStorage.setItem("loggedInEmail", email);
}
} catch (error) {
console.error('Error in fetching profile data:', error);
console.error("Error in fetching profile data:", error);
}
};

fetchData();
};
}
}, [googleAuthToken]);

/*
* Helpers
*/

const googleLogIn = useGoogleLogin({
onSuccess: tokenResponse => {
onSuccess: (tokenResponse) => {
setGoogleAuthToken(tokenResponse);
setIsGoogleAuthed(true);

localStorage.setItem(getGoogleAuthTokenKey(), JSON.stringify(tokenResponse));
localStorage.setItem(
getGoogleAuthTokenKey(),
JSON.stringify(tokenResponse)
);
},
scope: 'email profile https://www.googleapis.com/auth/gmail.readonly',
scope: "email profile https://www.googleapis.com/auth/gmail.readonly",
});

const googleLogOut = () => {
setIsScopesApproved(false);

setGoogleAuthToken(null);
localStorage.removeItem(getGoogleAuthTokenKey());

setIsGoogleAuthed(false);
localStorage.removeItem('isGoogleAuthed');
localStorage.removeItem("isGoogleAuthed");

setLoggedInGmail(null);
localStorage.removeItem('loggedInGmail');
localStorage.removeItem("loggedInGmail");

googleLogout();
};

Expand All @@ -151,4 +125,4 @@ const GoogleAuthProvider = ({ children }: ProvidersProps) => {
);
};

export default GoogleAuthProvider
export default GoogleAuthProvider;
8 changes: 0 additions & 8 deletions packages/app/src/hooks/useAccount.ts

This file was deleted.

0 comments on commit 6f24ad3

Please sign in to comment.