0

Setup :

  • Front end => React Native
  • Back end => Rails API

Context: I'm trying to create a user authentication flow using devise & devise-token-auth. My routes and requests seem to be working in the rails console & using Postman however I would like to now generate the responses to use in my frontend.

Key Question: How do I check if the signup params:

  • 1) have been entered
  • 2) are valid
  • 3) aren't duplicates

and then render a JSON status code that can be used in my front end?

module Users
  class RegistrationsController < Devise::RegistrationsController

...
  # POST /resource
  def create
      if params['user']['uid'].nil? && params['user']['provider'].nil?
        configure_permitted_parameters
        params['user']['uid'] = params['user']['email']
        params['user']['provider'] = 'email'
      end
      super
    end
end
...
  • You have to set devise to respond to json. Devise does all the validations automatically. [This article](https://medium.com/@eth3rnit3/crud-react-native-ror-backend-with-devise-auth-token-4407cac3aa0b) might be helpful – Ibraheem Ahmed May 18 '20 at 00:27
  • Unfortunately the links to all the code in that article aren’t working, so can’t see any examples which is frustrating. Thanks though! – Ryan McClure May 18 '20 at 08:21
  • How about [this one](https://learnetto.com/tutorials/react-devise-token-auth)? It's part of a much larger course, and has a repo is on github. It's regular react, not native, but the concepts should be helpful. – Ibraheem Ahmed May 18 '20 at 08:58
  • @Redline - Yes thank you! – Ryan McClure May 18 '20 at 11:16
  • This sounds like something that should be solved by adding [validations to the model](https://guides.rubyonrails.org/active_record_validations.html) and not in the controller. – max May 18 '20 at 12:16
  • @max thanks managed to sort it now – Ryan McClure May 18 '20 at 19:07

0 Answers0