How can I add my rails devise login/signup to a React Native app? How can I add my rails devise login/signup to a React Native app? reactjs reactjs

How can I add my rails devise login/signup to a React Native app?


you need to use the token authentication. Look at the Authentication section of this great tutorial, you'll find a basic implementation with the Devise: http://fancypixel.github.io/blog/2015/01/28/react-plus-flux-backed-by-rails-api/

Basically, once you have set up the token auth on the backend, you put a login form in your react native app, on submit you send the creds to the backend and receive the token which you then store in your app state (or you can persist it in asyncstore). Then you attach the token to each request to the backend in a HTTP header.


Have a look at this article where I wrote in depth how to achieve it:

https://medium.com/@sankalpsingha/creating-react-native-authentication-with-a-rails-backend-39d94e359984

Basically, you need to use Token Based Authentication system. For the Rails part, you can use a gem like the simple-token-auth. It extends on Devise and adds back the Token system in it.

Once that is done, you can use a fetch call to send your username and password and get back a Token from the server, which you can persist in the store. It is wise to use Redux for scenarios like this.

You can then use token to send all further requests to get into the authenticated routes.


You can also just do a basic authorization. React Native saves the cookie for you just like a normal browser. The only other thing you need is to save the CSRF token so you can make 'post' requests. If you only need 'get', you don't even need the csrf token.