Skip to content

Lambda - cookies are not retrievable via SSR #13520

@acidjazz

Description

@acidjazz

Environment

AWS Lambda -> API Gateway -> ( CloudFront / S3 )

Reproduction

I will update this w/ an example deployed setup as soon as I get time

Describe the bug

I set a token cookie when the user logs in - when I deploy to Lambda that cookie is undefined via SSR, but found on the client-side, this results in the bug of the layout rendering a page twice.

I use universal-cookie to set and retrieve these cookies

setting it:

  async login (result: UserLogin): Promise<undefined|string> {
    this.loggedIn.value = true
    this.token.value = result.token
    Object.assign(this.$user, result.user)
    this.cookies.set('token', this.token.value, { path: '/', maxAge: 60*60*24*30 })
...

retrieving it:

  private getToken(): string {
    if (this.config.req) return useCookie(this.config.req, 'token')
    return this.cookies.get('token')
  }

Additional context

This is only an issue with Lambda - ec2 and locally it works perffectly

Logs

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions