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

Token (cookie) is lost on refresh using Docker #718

Closed
julian-dueck opened this issue Mar 23, 2024 · 4 comments
Closed

Token (cookie) is lost on refresh using Docker #718

julian-dueck opened this issue Mar 23, 2024 · 4 comments
Labels
bug A bug that needs to be resolved needs-reproduction Action needed: A valid reproduction of the issue needs to be added provider-local An issue with the local provider

Comments

@julian-dueck
Copy link

Environment

  • Operating System: Windows_NT
  • Node Version: v20.11.1
  • Nuxt Version: 3.10.3
  • CLI Version: 3.10.1
  • Nitro Version: 2.9.1
  • Package Manager: [email protected]
  • Builder: -
  • User Config: runtimeConfig, devtools, modules, auth, colorMode, tailwindcss
  • Runtime Modules: @sidebase/[email protected], @nuxt/[email protected]
  • Build Modules: -

Reproduction

No reproduction, sorry. I think it's pretty straight forward.

Describe the bug

My app runs fine with npm run dev and npm run build until I dockerize it for production. I use the Dockerfile template provided by sidebase. I execute npm run build in the Dockerfile and run it with node /app/.output/server/index.mjs. I use local provider. When I log in with credentials, everything works fine, until I refresh the page and the token (cookie) is gone and the user is sent back to the login page. Is the vueApp being unmounted on refresh? Is the session data lost on refresh?

Additional context

Dockerfile

ARG NODE_VERSION=node:20.11.1

FROM $NODE_VERSION AS dependency-base

# create destination directory
RUN mkdir -p /app
WORKDIR /app

# copy the app, note .dockerignore
COPY package.json .
COPY package-lock.json .
RUN npm ci

FROM dependency-base AS production-base

# build will also take care of building
# if necessary
COPY . .
RUN npm run build

FROM $NODE_VERSION AS production

COPY --from=production-base /app/.output /app/.output

# Run in production mode
ENV NODE_ENV=production

Docker Compose

version: '3.9'

services:
  web:
    build: 
      context: .
    env_file:
      - .env
    ports:
      - "80:3000"
    command: node /app/.output/server/index.mjs

Is this a Docker issue? Did I do something wrong?

Logs

No response

@julian-dueck julian-dueck added bug A bug that needs to be resolved pending An issue waiting for triage labels Mar 23, 2024
@sandrinjoy
Copy link

I have also faced similar issue, the cookie gets removed on certain scenario.
So on refreshing & since there is no auth cookie , we take them to login page.
Weird part is that, after waiting for a few seconds, the cookie got restored, probably the authtoken api got hit.
After refreshing again, the user is logged in back.
@julian-dueck can you share your auth config ?

@julian-dueck
Copy link
Author

This is my auth config:

auth: {
  isEnabled: true,
  provider: {
    type: 'local',
    sessionDataType: {status: 'string', created: 'string', userInfo: {id: 'string', fullName: 'string', username: 'string'}},
  },
  session: {
    enableRefreshPeriodically: 10000,
    enableRefreshOnWindowFocus: true,
  },
  globalAppMiddleware: true,
}

In my case, the cookie does not get restored after waiting for a few minutes.

@zoey-kaiser zoey-kaiser added p4 Important Issue provider-local An issue with the local provider needs-reproduction Action needed: A valid reproduction of the issue needs to be added and removed pending An issue waiting for triage p4 Important Issue labels Mar 30, 2024
Copy link

Hello 👋

Please provide a reproduction for this issue 🙏

How can I create a reproduction?

Please use one of the following links to reproduce your issue.

Please ensure that the reproduction is as minimal as possible. This will allow us to isolate the issue as best as possible.

Here are some more amazing posts about the importance of reproductions:

@julian-dueck
Copy link
Author

Fixed the issue with these changes:
Added these 2 lines at the end of the Dockerfile

ENV NUXT_PORT=80
ENV PORT=80

Changed ports in docker-compose.yaml

    ports:
      - "80:80"

Now it works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug that needs to be resolved needs-reproduction Action needed: A valid reproduction of the issue needs to be added provider-local An issue with the local provider
Projects
None yet
Development

No branches or pull requests

3 participants