-
Notifications
You must be signed in to change notification settings - Fork 230
Open
Labels
enhancementNew feature or requestNew feature or requestto be implemented in v1This issue or pull request will be resolved in the v1 rework, but has not yet been completed.This issue or pull request will be resolved in the v1 rework, but has not yet been completed.
Description
I'd like to suggest adding a login!
method, that would behave like login
except it would raise an exception if the login fails.
This is similar to the save
/ save!
methods in Rails.
It would be helpful in cases where you want to code the "happy path", and handle exceptions separately. For instance instead of:
class Api::V1::SessionsController < ApplicationController
def create
if login(params[:email], params[:password])
render json: { message: "You're logged in!" }
else
render json: { message: "Wrong credentials" }
end
end
end
you could have:
class Api::V1::SessionsController < ApplicationController
rescue_from Sorcery::InvalidCredentials, with: :invalid_credentials
def create
login!(params[:email], params[:password])
render json: { message: "You're logged in!" }
end
private
def invalid_credentials
render json: { message: "Wrong credentials" }
end
end
A few notes:
- I used
render json
for the sake of simplicity but view templates would be used instead Sorcery::InvalidCredentials
is just a suggestion, I'm open to ideas for a better name
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestto be implemented in v1This issue or pull request will be resolved in the v1 rework, but has not yet been completed.This issue or pull request will be resolved in the v1 rework, but has not yet been completed.