発生している問題・エラーメッセージ
devise_token_authを使用したtoken認証でのログイン機能を実装したのですが、current_api_v1_userがnilになっており使えない
該当のソースコード
※UserテーブルではなくAgentテーブルを作成して使用しています。
application_controller.rb
class ApplicationController < ActionController::API include DeviseTokenAuth::Concerns::SetUserByToken skip_before_action :verify_authenticity_token, raise: false before_action :configure_permitted_parameters, if: :devise_controller? def configure_permitted_parameters devise_parameter_sanitizer.permit(:sign_up, keys: [:agent_companies_id, :last_name, :first_name, :last_name_syllabic_characters, :first_name_syllabic_characters, :email, :password]) #新規登録時に許可するパラメーターの指定 devise_parameter_sanitizer.permit(:sign_in, keys: [:agent_companies_id, :email, :password]) #ログイン時に許可するパラメーターの指定 end end
agents_controller.rb
class Api::V1::AgentsController < ApplicationController def index agent = Agent.all if current_api_v1_agent render json: current_api_v1_agent else render json: { agent: agent } end end def show if current_api_v1_agent render json: current_api_v1_agent else render json: { error: 'ログインしてません' }, status: :not_found end end end
試したこと
- application_controller.rbにinclude DeviseTokenAuth::Concerns::SetUserByTokenを追加して実行→変わらず
色々調べてみたのですが、原因がわからなかったのでどなたかご教示いただけると幸いです🙇♂️
補足情報(FW/ツールのバージョンなど)
Rails 6.0.3
devise 4.8.0
devise_token_auth 1.1.5
あなたの回答
tips
プレビュー