sidebase / nuxt-auth

Authentication built for Nuxt 3! Easily add authentication via OAuth providers, credentials or Email Magic URLs!
https://auth.sidebase.io
MIT License
1.27k stars 163 forks source link

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

Closed Birleyici closed 7 months ago

Birleyici commented 10 months ago

Environment

No response

Reproduction

No response

Describe the bug

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

Description:

Environment:

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:

Troubleshooting Done:

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_
github-actions[bot] commented 7 months ago

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. - https://stackblitz.com/github/nuxt/starter/tree/v3-stackblitz - https://codesandbox.io/s/github/nuxt/starter/v3-codesandbox 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: - [The Importance of Reproductions](https://antfu.me/posts/why-reproductions-are-required) - [How to Generate a Minimal, Complete, and Verifiable Example](https://stackoverflow.com/help/minimal-reproducible-example)
github-actions[bot] commented 7 months ago

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