0

I use devise_token_auth and devise gem in Rails about authentication.

create login function below(below code is vue.js).

 async login() {
            try {
                const response = await axios.post(import.meta.env.VITE_APP_API_BASE + '/auth/sign_in', {
                    email: this.email,
                    password: this.password,
                })
                Cookies.set('accessToken', response.headers["access-token"])
                Cookies.set('client', response.headers["client"])
                Cookies.set('uid', response.headers["uid"])

                return response
            } catch (error) {
                console.log({ error })
            }
        },

response can get (access-token, uuid, client can get).

But after above code execute, it is recognized as not logged in.

I executed below current_user_json method, rendered "Not logged in" message.

 class UserController < ApplicationController
    def current_user_json
        if user_signed_in?
            render json: { message: "logged in" }, status: 200
        else
            render json: { message: "Not logged in" }, status: 200
        end
    end
  end

Please tell me why and how to fix.

kuma
  • 15
  • 1
  • 3

0 Answers0