Commit 2676d821 authored by Kevin Kaminski's avatar Kevin Kaminski

[AFP-87] 🚧 Working on Local Storage and adding google info

parent f124ab85
...@@ -4,6 +4,9 @@ import './index.css'; ...@@ -4,6 +4,9 @@ import './index.css';
import App from './App'; import App from './App';
import reportWebVitals from './reportWebVitals'; import reportWebVitals from './reportWebVitals';
const storage = window.localStorage;
storage.setItem("loggedIn", "false");
ReactDOM.render( ReactDOM.render(
<React.StrictMode> <React.StrictMode>
<App /> <App />
......
...@@ -2,20 +2,8 @@ import React, { useState, useEffect } from 'react' ...@@ -2,20 +2,8 @@ import React, { useState, useEffect } from 'react'
import {AccountForm} from 'components' import {AccountForm} from 'components'
const AccountPage = () => { const AccountPage = () => {
// const [appState, setAppState] = useState(0);
// useEffect(() => {
// const apiUrl = 'http://localhost:8080/api/orders';
// fetch(apiUrl).then((response) => response.json())
// .then((data) => console.log('This is your data', data));
// }, [appState])
// const tester = ()=> {
// setAppState(appState + 1);
// }
return ( return (
<div> <div>
{/* <button onClick={tester}>{appState}</button> */}
<AccountForm /> <AccountForm />
</div> </div>
) )
......
import React from 'react' import React from 'react'
import { LoginForm } from 'components'; import { LoginForm } from 'components';
import { GoogleLogin } from 'react-google-login'; import { GoogleLogin, GoogleLogout } from 'react-google-login';
const AuthPage = () => { const AuthPage = () => {
const storage = window.localStorage;
const responseGoogle = (response: any) => { const responseGoogle = (response: any) => {
// console.log(response) console.log(response)
// console.log(response.profileObj); // console.log(response.profileObj);
// console.log(response.tokenObj); // console.log(response.tokenObj);
if ("error" in response) {
storage.setItem("loggedIn", "false")
} else {
const {email, familyName:lastName, givenName:firstName, googleId, imageUrl} = response.profileObj;
const googleAuthInfo = {
email,
firstName,
lastName,
googleId,
imageUrl
}
storage.setItem("loggedIn", "true");
storage.setItem("googleAuthInfo", JSON.stringify(googleAuthInfo));
return (googleAuthInfo);
}
}
const loginSuccess = (response: any) => {
console.log(response)
const {email, familyName:lastName, givenName:firstName, googleId, imageUrl} = response.profileObj; const {email, familyName:lastName, givenName:firstName, googleId, imageUrl} = response.profileObj;
return ({ const googleAuthInfo = {
email, email,
firstName, firstName,
lastName, lastName,
googleId, googleId,
imageUrl imageUrl
}) }
storage.setItem("loggedIn", "true");
storage.setItem("googleAuthInfo", JSON.stringify(googleAuthInfo));
return (googleAuthInfo);
}
const loginFailure = (response: any) => {
console.log(response);
storage.setItem("loggedIn", "false")
}
const logout = (response: any) => {
console.log(response)
storage.clear();
} }
return ( return (
...@@ -27,6 +59,12 @@ const AuthPage = () => { ...@@ -27,6 +59,12 @@ const AuthPage = () => {
onFailure={responseGoogle} onFailure={responseGoogle}
cookiePolicy={'single_host_origin'} cookiePolicy={'single_host_origin'}
/> />
{/* <GoogleLogout
clientId="658977310896-knrl3gka66fldh83dao2rhgbblmd4un9.apps.googleusercontent.com"
buttonText="Logout"
onLogoutSuccess={logout}
onFailure={logout}
/> */}
</div> </div>
) )
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment