devise_token_auth
devise_token_auth copied to clipboard
Multiple User Types - Group Authentication
Hi, I am using this gem with multiple users, and am getting a weird bug when trying to authenticate. I create a devise_token_auth_group that lets me authenticate multiple user types. However, neither of the if or elsif conditions below are met, although the before_action :authenticate_user! seems to pass for the index action (because it doesn't render or redirect and allows the index action to run). Any ideas if I am doing this wrong or missing something?
I am signed in as a shopper and should be getting all locations. At first, it works, and my batch request is set to 5 seconds, and i am requesting every 5 seconds to this action. Somehow, after letting this run for a while, @locations ends up being empty because neither the if or elsif conditions are met...
devise_token_auth_group :user, contains: [:shopper, :merchant]
before_action :authenticate_user!, except: [:update]
before_action :authenticate_merchant!, only: [:update]
def index
if merchant_signed_in?
@locations = Location.where(merchant_company_id: params[:merchant_company_id])
elsif shopper_signed_in?
@locations = Location.all
end
# the @locations variable sometimes has all locations (as expected)
# but after a bunch of sequential requests, it is empty so the action renders "null"
render json: @locations, status: 200
end
This leads me to believe the before action is not working properly. As a test, I tried just hitting this route using PostMan Rest Client without any access token, and somehow it returned an empty array, so I believe that is where the problem is.
that's because group auth is not working. I got the same problem here, it's not authenticating when I use group auth, although the :authenticate_user! is working just fine.
I'll look into this ASAP
@lynndylanhurley I'm happy to know that, let us know if you need any help!
Any update?
I got the same problem with
before_action :authenticate_member!
Any updates after 8 years?
because it s still not working...