Method: Devise::Rownd::AuthController#authenticate

Defined in:
app/controllers/devise/rownd/auth_controller.rb

#authenticateObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/devise/rownd/auth_controller.rb', line 13

def authenticate
  Devise::Rownd::Log.debug('handle /authenticate')
  access_token = params[:access_token]
  session_token = session['warden.user.user.key']
  new_access_token = session_token != access_token

  Devise::Rownd::Log.debug("/authenticate: new_access_token = #{new_access_token}")

  if !session_token.nil? && new_access_token
    # We have to log the user out otherwise warden will just serialize the user from session,
    # which currently holds the old access token
    warden.logout(:user)
  end

  warden.authenticate!(scope: :user)

  should_refresh_page = new_access_token
  Devise::Rownd::Log.debug("/authenticate: success, refresh = #{should_refresh_page}")

  render json: {
    message: 'Successfully authenticated user',
    should_refresh_page: should_refresh_page
  }, status: :ok
end