Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Built in cookie store broken in latest version? #674

Open
vincent-lu opened this issue Dec 23, 2021 · 4 comments
Open

Built in cookie store broken in latest version? #674

vincent-lu opened this issue Dec 23, 2021 · 4 comments

Comments

@vincent-lu
Copy link

Using 4.1.7 version with v2, and this is setup:

import Vue from "vue";

import auth from "@websanova/vue-auth/dist/v2/vue-auth.common.js";
import driverAuthBearer from "@websanova/vue-auth/dist/drivers/auth/bearer.js";
import driverHttpVueResource from "@websanova/vue-auth/dist/drivers/http/vue-resource.1.x.js";
import driverRouterVueRouter from "@websanova/vue-auth/dist/drivers/router/vue-router.2.x.js";

Vue.use(auth, {
  plugins: {
    http: Vue.http,
    router: Vue.router,
  },
  drivers: {
    auth: driverAuthBearer,
    http: driverHttpVueResource,
    router: driverRouterVueRouter,
  },
  options: {
    rememberkey: "auth_remember",
    tokenDefaultKey: "auth_token_default",
    tokenImpersonateKey: "auth_token_impersonate",
    stores: ["cookie", "storage"],
  },
});

And login simply does:

this.$auth
  .login({
    body: {
      email: "",
      password: "",
    },
    staySignedIn: true,
  })
  .then(...);

When the stores is set to ["cookie", "storage"] the login() does its job and fetch back correct jwt but doesn't store the token in either cookie or localStorage, then the user fetch fails because the request is missing the Authoriziation header.

If I change the stores to ["storage", "cookie"] or just remove stores option entirely, then it works fine.

@necessarylion
Copy link

I got same issue but only when origins are not same.

@zorn-v
Copy link
Contributor

zorn-v commented Jun 11, 2022

I think it because browsers changed their cookie policies.

@BennaceurHichem
Copy link

I had the same issue, I did a lot of workarounds but tokens still don't persist in both local storage and cookies, I tried to set cookies from my side in the login request before fetching the user but I couldn't, now I had an Unauthorized error for /user and the login is correctly passed, but due to cookies storage issue, the user data fetching didn't work properly.

In another nuxt project, I'm using nuxt-auth package and cookies work properly, i.e I don't think that it's a cookie policies @zorn-v.

does anyone know how to inherit the driver properly(to avoid implementing the driver into node_modules), and set cookies on my own using vue-cookie package.
I tried to set cookies from the node_modules folder of vue-auth, but I couldn't use vue-cookie for that.

@websanova
Copy link
Owner

@BennaceurHichem Hard to say, Did you try any tests independent of the library with just raw JS?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants