I just made a google login and logout function with react-google-login hook. It's working perfectly. but I want to add filter for customer emails. so specific customers should login with google. I tried to find the solution but couldn't find the solution yet. so I want to make specific customers to logout auto after they logged in. but how can I do that?
import React, {useState ,useEffect} from 'react';
import { GoogleLogin } from 'react-google-login';
import { useGoogleLogout } from 'react-google-login'
// refresh token
import { refreshTokenSetup } from '../api/refreshToken';
const clientId =
'xxx.com';
export const UserInfo = {
get uservalue() { return localStorage.getItem('user'); }
}
function Login() {
const onSuccess = (res) => {
console.log('Login Success: currentUser:', res.profileObj);
alert(
`Logged in successfully welcome ${res.profileObj.name} 😍. \n See console for full profile object.`
);
localStorage.setItem('user', res.profileObj.email);
if(res.profileObj.email !== 'abc@abc.com')
logout function // want to make logout function
refreshTokenSetup(res);
};
const onFailure = (res) => {
console.log('Login failed: res:', res);
alert(
`Failed to login`
);
};
return (
<div>
<GoogleLogin
clientId={clientId}
buttonText="Login"
onSuccess={onSuccess}
onFailure={onFailure}
cookiePolicy={'single_host_origin'}
style={{ marginTop: '100px' }}
isSignedIn={true}
/>
</div>
);
}
export default Login;