50 lines
1.0 KiB
Ruby
50 lines
1.0 KiB
Ruby
|
|
# frozen_string_literal: true
|
||
|
|
|
||
|
|
class Users::SessionsController < Devise::SessionsController
|
||
|
|
respond_to :json
|
||
|
|
# POST /resource/sign_in
|
||
|
|
# def create
|
||
|
|
# super
|
||
|
|
# end
|
||
|
|
|
||
|
|
# DELETE /resource/sign_out
|
||
|
|
# def destroy
|
||
|
|
# super
|
||
|
|
# end
|
||
|
|
|
||
|
|
private
|
||
|
|
|
||
|
|
def respond_with(resource, _opts = {})
|
||
|
|
puts
|
||
|
|
render json: {
|
||
|
|
status: { code: 200, message: 'Logged in successfully.' },
|
||
|
|
user: {
|
||
|
|
id: resource.id,
|
||
|
|
email: resource.email,
|
||
|
|
name: resource.name,
|
||
|
|
role: resource.role,
|
||
|
|
role_id: resource.role_id,
|
||
|
|
jti: resource.jti,
|
||
|
|
keychain: resource.keychain,
|
||
|
|
created_at: resource.created_at,
|
||
|
|
updated_at: resource.updated_at
|
||
|
|
}
|
||
|
|
}, status: :ok
|
||
|
|
end
|
||
|
|
|
||
|
|
def respond_to_on_destroy
|
||
|
|
if current_user
|
||
|
|
render json: {
|
||
|
|
status: 200,
|
||
|
|
message: "Logged out successfully."
|
||
|
|
}, status: :ok
|
||
|
|
else
|
||
|
|
render json: {
|
||
|
|
status: 401,
|
||
|
|
message: "Couldn't find an active session."
|
||
|
|
}, status: :unauthorized
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
end
|