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

I cannot access cookies I create when Logged in inside GetServerSideProps #564

Open
RamboGj opened this issue Nov 10, 2022 · 0 comments
Open

Comments

@RamboGj
Copy link

RamboGj commented Nov 10, 2022

Hey, I'm creating some cookies when user login in my app, to use these cookies for validate if user is logged in before access some page of my app. It was working, but suddenly my cookies stopped appearing inside getServerSideProps. I don't know why.

1 - I set the cookies inside login function
nookies.set(null, 'userAddress', res.data.result.address, { maxAge: 60 * 60 * 24, }) nookies.set(null, 'userSessionToken', res.data.result.sessionToken) setCookie(null, 'userAddress', res.data.result.address, { maxAge: 60 * 60 * 24, }) setCookie(null, 'userSessionToken', res.data.result.sessionToken)
2 - I try to get this cookies inside a page getServerSideProps
`
export const getServerSideProps: GetServerSideProps = async (ctx) => {
const cookies = nookies.get(ctx)
console.log('cookies => ', cookies)

if (cookies.userAddress?.length > 0) {
const isSessionTokenExpired = await verifyUserSessionTokenIsExpired(
cookies.userAddress,
cookies.userSessionToken,
)

console.log(isSessionTokenExpired)

if (isSessionTokenExpired) {
  nookies.destroy(undefined, 'userSessionToken')
  nookies.destroy(undefined, 'userAddress')
  return {
    props: {},
    redirect: {
      destination: '/dashboard/investors',
    },
  }
} else {
  return {
    props: {},
  }
}

} else {
return {
props: {},
redirect: {
destination: '/dashboard/investors',
},
}
}
}`

3 - Cookies does not appear anymore =>
Screenshot_12

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

1 participant