Rails + Devise + API + User Registration

I am new to rubies and rails, and so far I have managed to set up user management through development. Now I am trying to integrate support for mobile applications for Android and iOS. So far, they have managed to log in and log out and get an authentication token. But in addition to this, I would also like them to be able to register.

Now, as I understand it, I need to make a message for

http://localhost:3000/users/sign_up 

What does this post look like? And how do I get a JSON response? I found this on https://stackoverflow.com/a/318440/169 .

 "utf8=✓&authenticity_token=n5vXMnlzrXefnKQEV4SmVM8cFdHDCUxMYWEBMHp9fDw%3D&user[email]=asd%40fasd.org&user[password]=321&user[password_confirmation]=1233&commit=Sign+up" 

Unfortunately, this did not work - I get a "Bad Request" message. I also have some questions about this example. What is authenticity_token for? How to get it? This is not token authentication, which I assume, since the user cannot even have it at the moment.

In addition, after a successful login, I would like to associate the message with the registration with a successfully generated authentication token. Therefore, I assume that I need to somehow expand the existing development registration controller.

Thank you in advance!

+4
source share
1 answer

The developer already has all the settings. Based on your registration path, I conclude that you installed Devise at http://localhost:3000/users . The developer includes all the necessary controllers and views, including the registration form, registration form, email confirmation form, and password reset forms.

GET http://localhost:3000/users/sign_up is actually a form for users to register. The form on this page will POST to http://localhost:3000/users/ , which is sent to the Devise registration controller to create an action.

Assuming there is no action / view in /users/sign_up , the registration form should be there, go check if it exists (if you configured devise_for in the routes.rb file correctly).

+4
source

Source: https://habr.com/ru/post/1432936/


All Articles