back/app/controllers/sessions_controller.rb
# Handle the oAuth callback when signing in with an external provider (we
# currently only support facebook)
#
# TODO add unit tests all around this thing
Handle the oAuth callback when signing in with an external provider (we
currently only support facebook)


Handle the oAuth callback when signing in with an external provider ( we currently only support facebook )
def create
    if request.env['omniauth.auth']
      user = User.authenticate_with_omniauth(request.env['omniauth.auth'])
      session[:user_id] = user.id
      if request.env['omniauth.origin']
        return redirect_to request.env['omniauth.origin']
      end
      respond_to do |format|
        format.json do
          render json: {message: 'Successfully authenticated', user: user}, status: 200
        end
        format.html do
          return redirect_to root_url
        end
      end
    end
    respond_error 'Auth failed'
  end
def create if request . env [ 'omniauth.auth' ] user = User . authenticate_with_omniauth ( request . env [ 'omniauth.auth' ] ) session [ :user_id ] = user . id if request . env [ 'omniauth.origin' ] return redirect_to request . env [ 'omniauth.origin' ] end respond_to do | format | format . json do render json : { message : 'Successfully authenticated' , user : user } , status : 200 end format . html do return redirect_to root_url end end end respond_error 'Auth failed' end
Handle the oAuth callback when signing in with an external provider (we
currently only support facebook)
Handle the oAuth callback when signing in with an external provider ( we currently only support facebook )