Authentication in Ionic/Cordova App

前端 未结 2 810
北荒
北荒 2021-01-29 18:09

First off, I\'m no pro.

In my quest to become a better developer I am trying to understand what is needed and how to accomplish creating a sign-up/login for an Ionic-Fra

2条回答
  •  野的像风
    2021-01-29 19:06

    nathvarun gave a very complete answer, but I'd like to share the steps I do for authentication in my app.

    1. Send email + password via ajax to the server
    2. Generate a token in the server and send it back to the app
    3. Store email + token in localStorage
    4. For every single request I make to the server I send email + token via POST
    5. In the server I verify authenticity of that user with that token, if true the method is executed, if false I send back to the app an error (401)
    6. If app receives success, then it's ok, if receives error I redirect to login screen.

    Nice thing is that when the app is open, you can get the email + token from localStorage, send to the server, if that token is ok for that user, redirect to main screen, otherwise redirect to login. Then whenever user clears the cache of the app, he is redirected to login screen.

提交回复
热议问题