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

Issue with setTokenManager Server Middleware Not Working Properly in Vercel Deployment #587

Closed
Birleyici opened this issue Nov 28, 2023 · 2 comments
Labels
bug A bug that needs to be resolved closed-by-bot Closed by automation needs-reproduction Action needed: A valid reproduction of the issue needs to be added

Comments

@Birleyici
Copy link

Birleyici commented Nov 28, 2023

Environment

No response

Reproduction

No response

Describe the bug

Title: Issue with setTokenManager Server Middleware Not Working Properly in Vercel Deployment

Description:

Environment:

  • Framework & Version: Nuxt.js "^3.7.1"
  • Deployment Platform: Vercel
  • Node.js Version: v20.9.0
  • Relevant Packages/Libraries:
    {
    "name": "nuxt-app",
    "private": true,
    "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare"
    },
    "devDependencies": {
    "@nuxt/devtools": "latest",
    "@nuxtjs/google-fonts": "^3.0.2",
    "@sidebase/nuxt-auth": "^0.6.0-rc.0",
    "@types/node": "^18.17.3",
    "autoprefixer": "^10.4.14",
    "nuxt": "^3.7.1",
    "nuxt-api-party": "^0.20.0",
    "nuxt-icon": "^0.5.0",
    "postcss": "^8.4.27",
    "tailwindcss": "^3.3.3"
    },
    "dependencies": {
    "@nuxt/image": "^1.0.0-rc.2",
    "@pinia/nuxt": "^0.4.11",
    "@vueup/vue-quill": "^1.2.0",
    "jsonwebtoken": "^9.0.2",
    "mobile-detect": "^1.4.5",
    "next-auth": "^4.21.1",
    "nuxt-swiper": "^1.2.2",
    "nuxt3-select2": "^0.1.29",
    "ofetch": "^1.3.3",
    "pinia": "^2.1.6"
    },
    "overrides": {
    "vue": "latest"
    }
    }

Problem:
I have deployed my Nuxt.js project on Vercel and am encountering an issue with my setTokenManager server middleware, which is not functioning as expected. In my local environment, everything works fine, but in the Vercel deployment, the token is returned as null.

Code Snippet:

import { getToken } from '#auth'

export default defineEventHandler(async (event) => {
    console.log(event, "event")

    let token = await getToken({ event })
    console.log(token, "here")
    setCookie(event, 'token', token?.jwt, { httpOnly: true })
});

Issue Details:

  • The getToken function, when invoked, doesn't retrieve the expected token. Instead, it returns null.
  • This issue is only observed after deployment on Vercel. Locally, the function works as intended.
  • I have already ensured that the environment variables are correctly set up in Vercel.
  • The middleware seems to be getting executed, as logs within the function show the expected output for the event.

Troubleshooting Done:

  • Checked and verified all environment variables on Vercel.
  • Reviewed middleware configuration for any discrepancies between local and production environments.
  • Ensured that there is no issue with cookie handling in the setCookie function.

Additional Context:
Here is the console output of the event object:

H3Event {
  __is_event__: true,
  node: {
    req: IncomingMessage {
      _readableState: [ReadableState],
      _events: [Object: null prototype] {},
      _eventsCount: 0,
      _maxListeners: undefined,
      socket: [Socket],
      httpVersionMajor: 1,
      httpVersionMinor: 1,
      httpVersion: '1.1',
      complete: true,
      rawHeaders: [Array],
      rawTrailers: [],
      joinDuplicateHeaders: null,
      aborted: false,
      upgrade: false,
      url: '/api/auth/session?callbackUrl=***',
      method: 'GET',
      statusCode: null,
      statusMessage: null,
      client: [Socket],
      _consuming: false,
      _dumped: false,
      originalUrl: '/api/auth/session?callbackUrl=***',
      [Symbol(kCapture)]: false,
      [Symbol(kHeaders)]: [Object],
      [Symbol(kHeadersCount)]: 66,
      [Symbol(kTrailers)]: null,
      [Symbol(kTrailersCount)]: 0
    },
    res: ServerResponse {
      _events: [Object: null prototype],
      _eventsCount: 1,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: false,
      _last: false,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      maxRequestsOnConnectionReached: false,
      _defaultKeepAlive: true,
      useChunkedEncodingByDefault: true,
      sendDate: true,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      strictContentLength: false,
      _contentLength: null,
      _hasBody: true,
      _trailer: '',
      finished: false,
      _headerSent: false,
      _closed: false,
      socket: [Socket],
      _header: null,
      _keepAliveTimeout: 5000,
      _onPendingData: [Function: bound updateOutgoingData],
      req: [IncomingMessage],
      _sent100: false,
      _expect_continue: false,
      _maxRequestsPerSocket: 0,
      [Symbol(kCapture)]: false,
      [Symbol(kBytesWritten)]: 0,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype],
      [Symbol(errored)]: null,
      [Symbol(kHighWaterMark)]: 16384,
      [Symbol(kRejectNonStandardBodyWrites)]: false,
      [Symbol(kUniqueHeaders)]: null
    }
  },
  web: undefined,
  context: { _nitro: { routeRules: {} }, nitro: { errors: [] } },
  _method: undefined,
  _path: '/api/auth/session?callbackUrl=***',
  _headers: undefined,
  _requestBody: undefined,
  _handled: false,
  fetch: [Function (anonymous)],
  '$fetch': [Function (anonymous)],
  waitUntil: [Function (anonymous)],
  captureError: [Function (anonymous)]
} event```

I am at a loss for what might be causing this issue and would appreciate any guidance or suggestions on how to resolve it. Has anyone else faced a similar issue, or does anyone have insights on what might be going wrong here?

Thank you in advance for your assistance!


### Additional context

_No response_

### Logs

_No response_
@Birleyici Birleyici added the bug label Nov 28, 2023
@zoey-kaiser zoey-kaiser added bug A bug that needs to be resolved needs-reproduction Action needed: A valid reproduction of the issue needs to be added and removed bug needs-reproduction Action needed: A valid reproduction of the issue needs to be added labels Feb 23, 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:

Copy link

github-actions bot commented Mar 9, 2024

This issue was closed because it was open for 14 days without a reproduction.

@github-actions github-actions bot added the closed-by-bot Closed by automation label Mar 9, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 9, 2024
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 closed-by-bot Closed by automation needs-reproduction Action needed: A valid reproduction of the issue needs to be added
Projects
None yet
Development

No branches or pull requests

2 participants