1

How can i access rails sorcery methods in my RESTFULL API File.

desc 'Signin' post "signin_api" do

  if @user = User.authenticate(params[:email], params[:password])
      @user.set_authentication_token
      @current_user = User.find(@user)
      status 200
      debugger
     # login(params[:email], params[:password])
     #login_user(@user)
     current_user
ayesha kaleem
  • 77
  • 2
  • 7

1 Answers1

0

Although not using Grape, I was running into a similar issue of Sorcery methods not being recognized in a Rails 5.2 api.

Adding include Sorcery::Controller to the top of my SessionsController resolved my issue.

Example:

module Api
  module V1
    class SessionsController < ApplicationController
      include Sorcery::Controller

      def create 
       @user = login(params[:email], params[:password])
       .
       .
       .
      end
    end
  end
end

Source: Last response in Sorcery issues #47

sirramongabriel
  • 583
  • 1
  • 11
  • 27