I used knock, which is a gem that creates jwt, to create an authentication function between ios and Rails. I want to be logged in at the same time as the successful creation of a new user, but the initial flow of new user registration is
① Create a new user with user / create. → Returns user information.
(2) Put the user information in the request body, send a post request to user_token, receive jwt, and log in.
I had to hit the API twice. I want to do this once by making the user / create response jwt.
I did the following.
python
def create
user = User.new(user_params)
if user.save
token = Knock::AuthToken.new payload: { sub: user.id }
render status: :created, json: token
else
render status: :unprocessable_entity, json: { messages: user.errors.messages }
end
end
You only have to do this once!
Recommended Posts