-
Notifications
You must be signed in to change notification settings - Fork 2
Auth #33
Conversation
@token = encode_token({ user_id: @user.id }) | ||
time = Time.now + 2.hours.to_i | ||
render json: { user: UserSerializer.new(@user), jwt: @token, exp: time }, status: :created |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify the intent here, but is the reason why you're returning a JWT token here as well because when a user registers, it should also automatically log them in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is how the behavior is now just so you don't need to take two steps. It can easily be changed later if we don't want that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it the way you did it. Just making sure I'm understanding it correctly
def user_login_params | ||
params.require(:user).permit(:username, :password) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will require the frontend to send a JSON object in the following format:
{
"user": {
"username": "test3",
"password": "testpw3"
}
}
Nothing wrong with this functionality-wise, but just making sure that this is how you want it to be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that is how I wrote it and tested it. We can just accept the username and password instead of a user json if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This way is fine. We just have to make sure the frontend people know the POST body should look like this for login
Add /register and /login endpoints
/register
/login