Skip to content

Instantly share code, notes, and snippets.

@emilsoman
Created May 18, 2013 12:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emilsoman/5604222 to your computer and use it in GitHub Desktop.
Save emilsoman/5604222 to your computer and use it in GitHub Desktop.
Customized SessionsController to render custom JSON on successful sign in
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