##概要
現在、RailsAPIの開発を行っており、クライアント側のフォームからログインするリクエストを送り、showアクション内で、deviseのcurrent_userを利用して現在ログイン中のユーザー情報を反映するという実装をしております。
ユーザーを複数登録したのち、それぞれのアカウント名とパスワードでログインを行なったのですが、以前に登録、ログインを行なったユーザーの情報が反映されています。この問題に関してどのように考えれば良いかご教示いただけますと幸いです。
##疑問点
ログアウト処理もきちんと実装しておかないと、Sessionが残ったままで、別のメールアドレス&パスワードの組み合わせを投げても、以前のユーザー情報が返ってきますので、注意が必要です。
引用http://qiita.com/fuji_syan/items/9593d3ae644cb26a4d28
上のリンクにこのような記述もあったのですが、その場合複数のユーザーが同時にログインした際はどうなるのか疑問に感じました。
##コード
app/controllers/sessions_controller.rb
class SessionsController < ApplicationController skip_before_action :authenticate_user_from_token! def create @user = User.find_by(name: params[:name]) return invalid_name unless @user if @user.valid_password?(params[:password]) sign_in :user, @user render json: @user, serializer: SessionSerializer, root: nil else invalid_password end end def destroy user = User.find(params[:name]) if sign_out(user) render :json => {success: true} else render :json => {success: false} end end private def invalid_name warden.custom_failure! render json: { error: t('invalid_name') } end def invalid_password warden.custom_failure! render json: { error: t('invalid_password') } end end
app/controllers/users_controller.rb
class UsersController < ApplicationController skip_before_action :authenticate_user_from_token!, only: [:create] def show @user = User.find_by(current_user) render json: @user, each_serializer: UserSerializer end ~省略~

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/09/15 06:49