devise_token_auth icon indicating copy to clipboard operation
devise_token_auth copied to clipboard

Multiple User Types - Group Authentication

Open ksinghal opened this issue 10 years ago • 6 comments

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

ksinghal avatar Jun 27 '15 16:06 ksinghal

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.

ksinghal avatar Jun 29 '15 14:06 ksinghal

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.

betoharres avatar Nov 11 '15 19:11 betoharres

I'll look into this ASAP

lynndylanhurley avatar Nov 11 '15 20:11 lynndylanhurley

@lynndylanhurley I'm happy to know that, let us know if you need any help!

betoharres avatar Nov 12 '15 13:11 betoharres

Any update? I got the same problem with before_action :authenticate_member!

nevedimko avatar Jun 20 '16 06:06 nevedimko

Any updates after 8 years?
because it s still not working...

SzymonB77 avatar Jan 08 '23 17:01 SzymonB77