Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
934 views
in Technique[技术] by (71.8m points)

vue.js - How Can I Share Cookies With Subdomain in Nuxt?

I have a subdomain for the partner dashboard and normal site. Both of are nuxt project.

Site : example.com

Subdomain: partner-dashboard.example.com

Cookie Plugin: https://www.npmjs.com/package/cookie-universal-nuxt

If the user logged in, I set user information as a cookie for both of them and then redirecting the user to the dashboard. But there are no user cookies on the redirected subdomain project?

Example.com Cookie set and Redirect to Dashboard Func:

// set cookie
      this.$cookies.set('user', JSON.stringify(loginData))
      this.$cookies.set('user', JSON.stringify(loginData), {
        domain: 'partner-dashboard.example.com'
      })

setTimeout(() => {
          window.location = 'https://partner-dashboard.example.com'
        }, 1000)

partner-dashboard.example.com Middleware:

export default function({ app, redirect }) {
  const user = app.$cookies.get('user')
  if (user && user.registered) {
    redirect('/dashboard')
  }
}

I want If the user logged in to the normal site, redirect to the dashboard with the user cookie. Then middleware can redirect it to inside because the user cookie is not null.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...