Created
May 18, 2013 12:15
-
-
Save emilsoman/5604222 to your computer and use it in GitHub Desktop.
Customized SessionsController to render custom JSON on successful sign in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Api | |
module V1 | |
module CustomDevise | |
class SessionsController < Devise::SessionsController | |
prepend_before_filter :require_no_authentication, :only => [:create ] | |
include Devise::Controllers::Helpers | |
respond_to :json | |
def create | |
self.resource = warden.authenticate!(auth_options) | |
sign_in(resource_name, resource) | |
resource.reset_authentication_token! | |
resource.save! | |
render json: { | |
auth_token: resource.reset_authentication_token, | |
user_role: resource.role | |
} | |
end | |
def destroy | |
sign_out(resource_name) | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment