CapacitorGoogleAuth icon indicating copy to clipboard operation
CapacitorGoogleAuth copied to clipboard

How to use the plugin for Autologin ?

Open Epameinondas-Theodoropoulos opened this issue 3 years ago • 6 comments

So I do not have a problem with the sign in. But I cannot understand what is the right flow for an autologin. When The user use the app for the first time I take the credentials and the tokens from the GoogleAuth.signIn() method and i send them to my backend and also i store them in the localStorage. When the user tries again to open the app I want to log in without inserting their credentials again.

I mean I do not have a way to check if the IdToken is expired. So when the user try to enter in my app I just use the GoogleAuth.signIn() method again. And I take the new tokens and I send them to my backend and i store them again in my localStorage. Is this wrong or not ?

Can you suggest another flow if this is wrong ?

I have checked the GoogleAuth.refresh() method and works but i cannot understand how to use it for my app to implement the autologin.

I use Ionic 6 with Capacitor 4 and Angular 13

Hello! I'm in the same situation. I call google apis from the backend so I send the serverAuthCode to by backend and call apis and it's working but after some times the token expire and I don't know how to renew it. in my case, calling GoogleAuth.refresh() on android produce this error: Error: I don't know how to refresh token on Android. Anyone can help us?

davidecampello avatar Sep 28 '22 11:09 davidecampello

I could not find something so far..

looking at the code the plugin doesn't implement refresh token for android? i know go figure.

choffmeyer avatar Nov 30 '22 01:11 choffmeyer

That is the android code I see in the code base so I assume it's not implemented but curious if that is the error message you get back?

@PluginMethod() public void refresh(final PluginCall call) { call.reject("I don't know how to refresh token on Android"); }

choffmeyer avatar Nov 30 '22 21:11 choffmeyer

No, I am not using android, I am using iOS. I get back Error: Uncaught (in promise): Error: User not logged in.

This is after the token expires or I close the app and reopen it. Its almost as if the plugin is losing all the previous session data and I need to store it and pass it back in or something, because the refresh works if I do it right after a signIn

ucjallen avatar Nov 30 '22 21:11 ucjallen

I think I got it figured out, check out my post https://github.com/CodetrixStudio/CapacitorGoogleAuth/issues/241

ucjallen avatar Dec 01 '22 02:12 ucjallen