简体   繁体   中英

Using Nuxt-Auth with Cookie

I am attempting to get Nuxt.js to work with cookie authentication. I am using nuxt-auth with cookie setting. Laravel Backend with Passport.

The reason I need to use Cookies is because I plan on having the nuxt project be on my main domain name (with login) and then having app.mydomainname.com for the actual application. The main website has public facing pages that use authentication as well.

Here is my config for nuxt.js for nuxt-auth:

  auth: {
    local: false,
    redirect: {
      login: "/login",
      logout: "/login",
      callback: "/login",
      home: false,
    },
    strategies: {
      cookie: {
        token: {
          property: "data.access_token",
        },
        user: {
          property: "data",
        },
        endpoints: {
          login: {
            url: "v1/auth/login",
            method: "post",
            propertyName: "access_token",
          },
          logout: { url: "/v1/auth/logout", method: "delete" },
          user: { url: "/v1/settings", method: "get" },
        },
      },
    },
  },

Login works fine, but then the cookie does not set when I look in my editthiscookie chrome plugin, thus the call to /settings does not work:

FineMyCookie Chrome 插件

As you see the cookie is just being set to true and not the access token.

Any help with the configuration would be helpful.

Thanks

Figured it out. I had to set set required: true and type: "Bearer" in the token config.

So it looks like this now:

auth: {
    redirect: {
      login: "/login",
      logout: "/login",
      callback: "/login",
      home: false,
    },
    strategies: {
      local: false,
      cookie: {
        token: {
          property: "data.access_token",
          required: true,
          type: "Bearer",
        },
        user: {
          property: "data",
        },
        endpoints: {
          login: {
            url: "v1/auth/login",
            method: "post",
          },
          logout: { url: "/v1/auth/logout", method: "delete" },
          user: { url: "/v1/settings", method: "get" },
        },
      },
    },
  },

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM