adrianhajdin / project_shareme_social_media

Image Sharing Social Media App
https://share-me-sanity.netlify.app/
1.73k stars 425 forks source link

Solution for google OAuth new update #27

Open AKzar1el opened 1 year ago

AKzar1el commented 1 year ago

I have a functional template of your code with the new standard of implementing OAuth and decoding it with jwt. I would love to contribute if you give me the option.

Amr-Ismail-95 commented 1 year ago

can you share it ? at least the log out part because im stuck there :(

mide2020-16 commented 1 year ago

I am also stuck there but you can find it in the comment section he made another video about that

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Amr Ismail Abdelkader Mohammed @.> Sent: Sunday, November 20, 2022 10:48:36 PM To: adrianhajdin/project_shareme_social_media @.> Cc: Subscribed @.***> Subject: Re: [adrianhajdin/project_shareme_social_media] Solution for google OAuth new update (Issue #27)

can you share it ? at least the log out part because im stuck there :(

— Reply to this email directly, view it on GitHubhttps://github.com/adrianhajdin/project_shareme_social_media/issues/27#issuecomment-1321251445, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ASJ2DDU7XVBYYURPKR47EETWJKMDJANCNFSM6AAAAAAR3ZZ37Y. You are receiving this because you are subscribed to this thread.Message ID: @.***>

mmatrevi commented 1 year ago

Solution to Logout issue

  1. Install and import this npm package

    import { gapi } from "gapi-script"; import { GoogleLogout } from "react-google-login";

  2. Add this function to your code

    useEffect(() => { function start() { gapi.client.init({ clientId:"INSERT YOUR GOOGLE CLIENT ID HERE" scope: "", }); } gapi.load("client:auth2", start); });

  3. Setup your google button like this

    <GoogleLogout clientId={process.env.REACT_APP_GOOGLE_API_TOKEN} render={(renderProps) => ( <button type="button" className=" bg-white p-2 rounded-full cursor-pointer outline-none shadow-md" onClick={renderProps.onClick} disabled={renderProps.disabled}

    )} onLogoutSuccess={logout} cookiePolicy="single_host_origin" />

Amr-Ismail-95 commented 1 year ago

That's the old way ... Google changed that

prachip1 commented 1 year ago

I simply created a button for logout and did this on onClick of this button.

const logout = ( ) =>{ localStorage.clear(); sessionStorage.clear();

navigate('/login'); }

It worked for me.