Sorcery methods are not available in RESTFULL web services grapes file rails 4

82 Views Asked by At

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
1

There are 1 best solutions below

0
sirramongabriel On

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