Class: AuthenticationController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- AuthenticationController
- Defined in:
- lib/generators/auth/templates/authentication_controller.rb
Instance Method Summary collapse
-
#login ⇒ Object
POST /auth/login.
Instance Method Details
#login ⇒ Object
POST /auth/login
7 8 9 10 11 12 13 14 15 |
# File 'lib/generators/auth/templates/authentication_controller.rb', line 7 def login @user = User.find_by_email(params[:email]) if @user&.authenticate(params[:password]) token = jwt_encode(user_id: @user.id) render json: { token: token }, status: :ok else render json: { error: 'unauthorized' }, status: :unauthorized end end |