Skip to content

Commit e03755d

Browse files
committed
Add login method for API on AuthenticationController
1 parent 6759dae commit e03755d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
class Api::V1::AuthenticationController < ApplicationController
2+
include JsonWebToken
3+
4+
skip_before_action :verify_authenticity_token
25

36
def login
7+
@user = User.find_by_email(params[:email])
8+
if @user.valid_password? params[:password]
9+
token = jwt_encode(user_id: @user.id)
10+
render json: { token: }, status: :ok
11+
else
12+
render json: { error: 'Unauthorized' }, status: :unauthorized
13+
end
414
end
515
end

0 commit comments

Comments
 (0)