lynndylanhurley / lynndylanhurley/devise_token_auth
Multiple User Types - Group Authentication
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 3.6k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
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
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the index action and its authenticate_user!, authenticate_merchant!, merchant_signed_in?, and shopper_signed_in? entry points. Reproduce the sequential requests using devise_token_auth_group with shopper authentication, then inspect why the signed-in predicate becomes false after repeated requests. Done means the correct locations are returned consistently and the failing authentication behavior is covered by an appropriate test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rails, ruby
- Domain
- api, authentication, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100