Class: Shakha::SessionController

Inherits:
ApplicationController show all
Defined in:
app/controllers/shakha/session_controller.rb

Instance Method Summary collapse

Instance Method Details

#checkObject



37
38
39
40
41
42
43
# File 'app/controllers/shakha/session_controller.rb', line 37

def check
  if signed_in?
    render json: { status: "active" }
  else
    render json: { status: "expired" }, status: :unauthorized
  end
end

#exchangeObject

POST /session/exchange — swap a one-time code for the session token.



8
9
10
11
12
13
14
15
16
# File 'app/controllers/shakha/session_controller.rb', line 8

def exchange
  session_record = Shakha::Session.exchange(params[:code])
  if session_record
    render json: { token: session_record.token,
                   expires_at: session_record.expires_at.iso8601 }
  else
    render json: { error: "Invalid or expired code" }, status: :unauthorized
  end
end

#showObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/shakha/session_controller.rb', line 18

def show
  unless signed_in?
    return render json: { error: "Authentication required" }, status: :unauthorized
  end

  render json: {
    user: {
      id: current_user.id,
      email: current_user.email,
      name: current_user.name,
      picture: current_user.picture,
      provider: current_user.provider
    },
    session: {
      expires_at: current_session.expires_at.iso8601
    }
  }
end