Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

417
Views
react-google-login hook, auto logout in react.js

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;
about 4 years ago ยท Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!