Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I've built out a React Native app which uses my Rails app as a back end, and I have gotten to the point where I need to get authentication working. The user needs to be able to log in the same way they would via the rails app which uses Devise. I am unclear how to implement that in React Native/iOS.

like image 381
spitfire109 Avatar asked Jun 23 '15 14:06

spitfire109


People also ask

How do you integrate social login in react native?

Ensure the "Google" sign-in provider is enabled on the Firebase Console. import { GoogleSignin } from '@react-native-google-signin/google-signin'; GoogleSignin. configure({ webClientId: '', }); Once initialized, setup your application to trigger a sign-in request with Google using the signIn method.

How do you add react to existing rails app?

First, you need to add the gem to your gemfile by running the command gem 'react-rails' and install the gem by running bundle install and react-rails installation script: rails g react:install . These actions will create a directory for the components and manifest file, and add them to the application.


1 Answers

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.

like image 123
michalvalasek Avatar answered Sep 17 '22 15:09

michalvalasek