capacitor-community / facebook-login

Facebook Login support
MIT License
103 stars 52 forks source link

How to achieve Autlogin #106

Open Epameinondas-Theodoropoulos opened 1 year ago

Epameinondas-Theodoropoulos commented 1 year ago

How to use the plugin achive an autologin for the user.

I mean now after the login I take the userId and the token. I send them to my server and I save them to my localStorage. Ok now the user closes the app and opens it again. Now I just send a new token that is generated from the server. I cannot find a workaround to reauthorize the user. The reauthorize() method do not work but still I cannot understand what is the right flow.

Can anyone suggest a flow for this ?. I cannot find something about that.

I use Ionic 5, Capacitor 4 and Angular 13

ciccilleju commented 1 year ago

I think you must do this kind of operation via backend, store the token and in your app check if the user has that token, in that case you can grant the access.

Epameinondas-Theodoropoulos commented 1 year ago

@ciccilleju But with every login is a different token. If I store the token in localStorage and send it to my backend How Will I know if this token is valid? The user must login again to check if the token that sends to me is the same. But as I said the token may change after some logins.

ciccilleju commented 1 year ago

no, that's not how it works.

this is the flow: 1) you call facebook's api getting a token and check if everything's fine in your backend (server side) 2) you store that token in your database 3) you send a "ok, this is the token, this token is good," to your client (your app) and you store it in locale storage. 4) when you access the app, you do a "get the token " from your local storage and send it to your backend, if the token is good->access the app, otherwise redirect to login page

Epameinondas-Theodoropoulos commented 1 year ago

@ciccilleju Oh now I understand. Ok thank you for the detailed answer and the steps. This was very helpful 👍

ciccilleju commented 1 year ago

no problems! :) glad to be helpful