How would user login authentication work with React native?

Loading...

How would user login authentication work with React native?

What would be the safest and the best approach to allowing a user to login to an app using their login details from a web server on a React native app. I assume using Fetch to POST data to a server would be the only way to transmit the data. Is there any encryption that ships with React native or Fetch? and would it be best to use a token based system so the server would pass back a token which React Native would then store as a global prop which could be called upon subsequent data requests to check if the user is still logged in? Also how would login stay persistent if the user left the app? Thanks for any responses in advance!

Solutions/Answers:

Answer 1:

Like Ryan mentioned the fetch api will work over SSL. I think a token based approach is the most flexible because you can then persist the login status within the app by storing the token on the device using react natives AsyncStorage api. If you need to communicate with your web app through a webview you can pass the token and authorize the request as needed.

The AsyncStorage api is based on the browsers localStorage api except it’s wrapped in a promise.

Answer 2:

The safest would be over SSL. You can certainly use SSL with a fetch() call. As for logging in, I implemented a React Native Login example that uses a WebView to login to your existing backend. Check this out and see if it solves your issue: https://github.com/ryanmcdermott/react-native-login

References

Loading...