ruby on rails - Multiple User Types - Group Authentication - Devise Token Auth -


i using devise token auth gem (https://github.com/lynndylanhurley/devise_token_auth) multiple users, , getting weird bug when trying authenticate. create devise_token_auth_group lets me authenticate multiple user types. however, neither of if or elsif conditions below met, although before_action :authenticate_user! seems pass index action (because doesn't render or redirect , allows index action run). ideas if doing wrong or missing something?

i signed in shopper , should getting locations when send request action. @ first, locations. however, after repeatedly accessing server every 5 seconds, @locations ends being empty because neither if or elsif conditions met... leads me believe before action not working properly. test, tried hitting route using postman rest client without access token, , somehow returned empty array, believe problem is.

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      # @locations variable has locations (as expected)     # after bunch of sequential requests, empty action renders "null"     render json: @locations, status: 200 end 

for index action, call :authenticate_user! helper, so, in action, can access user_signed_in? , current_user helpers, generated authenticate_user! call.

according this part of gem code, can read authenticate_xxx!, xxx_signed_in , current_xxx generated devise_token_auth_group xxx, user.

in case, can access helpers generated devise_token_auth_group name as:

  • authenticate_user!
  • user_signed_in?
  • current_user
  • current_users

a way change code this:

devise_token_auth_group :user, contains: [:shopper, :merchant] before_action :authenticate_user!, except: [:update] before_action :authenticate_merchant!, only: [:update]  def index     if current_user.is_a? shopper         @locations = location.where(merchant_company_id: params[:merchant_company_id])     elsif current_user.is_a? merchant         @locations = location.all     end      # @locations variable has locations (as expected)     # after bunch of sequential requests, empty action renders "null"     render json: @locations, status: 200 end 

more documentation here


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -