Error when using auth.js as a provider in auth #707
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
Environment
npx nuxi info
Reproduction
I have used authjs as a provider for protecting pages and authentication. This is the auth " auth: {
isEnabled: true,
provider: {
type: 'authjs'
},
globalAppMiddleware: {
isEnabled: true
}
}," snippet I have written in nuxt.config.ts. And on the server side I have made api in api/auth/[...].ts which handles auth as follows:
import { NuxtAuthHandler } from '#auth'
import CredentialsProvider from "next-auth/providers/credentials";
import { NitroFetchOptions } from "nitropack";
import { Messages } from "../../../util/Messages";
import { StatusCode } from "../../../util/Constants";
const config = useRuntimeConfig();
export default NuxtAuthHandler({
secret: 'jvA2sahdchdhhvsahdsdsdcddc' ?? 'test-123',
pages: {
// Change the default behavior to use
/login
as the path for the sign-in pagesignIn: '/login'
},
providers: [
// ... your provider configuration
CredentialsProvider.default({
name: "Credentials",
credentials: {
username: { label: 'Username', type: 'text', placeholder: '(hint: tom)' },
password: { label: 'Password', type: 'password', placeholder: '(hint: asdf1234)' }
},
async authorize(credentials: { username: string, password: string }) {
let serverTokens = (config.serverTokens).split(',');
let serverToken = serverTokens[Math.floor(Math.random() * serverTokens.length)];
}). I am having an error on server side "[nuxt] [request error] [unhandled] [500] Cannot set headers after they are sent to the client
at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
at new NodeError (node:internal/errors:405:5)
at ServerResponse.setHeader (node:_http_outgoing:648:11)
at setResponseHeaders (./node_modules/h3/dist/index.mjs:778:20)
at Object.handler (./node_modules/nitropack/dist/runtime/renderer.mjs:31:7)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.handler (./node_modules/h3/dist/index.mjs:1962:19)
at async Server.toNodeHandle (./node_modules/h3/dist/index.mjs:2249:7)"
when authentication process is going. These are the sequence of urls which are calling on the server side "url URL {
href: 'https://localhost:3000/',
origin: 'https://localhost:3000',
protocol: 'https:',
username: '',
password: '',
host: 'localhost:3000',
hostname: 'localhost',
port: '3000',
pathname: '/',
search: '',
searchParams: URLSearchParams {},
hash: ''
}
url URL {
href: 'https://localhost:3000/api/auth/session?callbackUrl=http:%2F%2Flocalhost:3000%2F',
origin: 'https://localhost:3000',
protocol: 'https:',
username: '',
password: '',
host: 'localhost:3000',
hostname: 'localhost',
port: '3000',
pathname: '/api/auth/session',
search: '?callbackUrl=http:%2F%2Flocalhost:3000%2F',
searchParams: URLSearchParams { 'callbackUrl' => 'http://localhost:3000/' },
hash: ''
}
url URL {
href: 'https://localhost:3000/api/auth/providers',
origin: 'https://localhost:3000',
protocol: 'https:',
username: '',
password: '',
host: 'localhost:3000',
hostname: 'localhost',
port: '3000',
pathname: '/api/auth/providers',
search: '',
searchParams: URLSearchParams {},
hash: ''
}
[nuxt] [request error] [unhandled] [500] Cannot set headers after they are sent to the client
at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
at new NodeError (node:internal/errors:405:5)
at ServerResponse.setHeader (node:_http_outgoing:648:11)
at setResponseHeaders (./node_modules/h3/dist/index.mjs:778:20)
at Object.handler (./node_modules/nitropack/dist/runtime/renderer.mjs:31:7)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.handler (./node_modules/h3/dist/index.mjs:1962:19)
at async Server.toNodeHandle (./node_modules/h3/dist/index.mjs:2249:7)
url URL {
href: 'https://localhost:3000/login',
origin: 'https://localhost:3000',
protocol: 'https:',
username: '',
password: '',
host: 'localhost:3000',
hostname: 'localhost',
port: '3000',
pathname: '/login',
search: '',
searchParams: URLSearchParams {},
hash: ''
}
url URL {
href: 'https://localhost:3000/api/auth/session?callbackUrl=http:%2F%2Flocalhost:3000%2Flogin',
origin: 'https://localhost:3000',
protocol: 'https:',
username: '',
password: '',
host: 'localhost:3000',
hostname: 'localhost',
port: '3000',
pathname: '/api/auth/session',
search: '?callbackUrl=http:%2F%2Flocalhost:3000%2Flogin',
searchParams: URLSearchParams { 'callbackUrl' => 'http://localhost:3000/login' },
hash: ''
}
"
Describe the bug
I am using authjs as a provider in auth in nuxt.config.ts and during the initial authentication steps sequence of api calls done "url URL {
href: 'https://localhost:3000/',
origin: 'https://localhost:3000',
protocol: 'https:',
username: '',
password: '',
host: 'localhost:3000',
hostname: 'localhost',
port: '3000',
pathname: '/',
search: '',
searchParams: URLSearchParams {},
hash: ''
}
url URL {
href: 'https://localhost:3000/api/auth/session?callbackUrl=http:%2F%2Flocalhost:3000%2F',
origin: 'https://localhost:3000',
protocol: 'https:',
username: '',
password: '',
host: 'localhost:3000',
hostname: 'localhost',
port: '3000',
pathname: '/api/auth/session',
search: '?callbackUrl=http:%2F%2Flocalhost:3000%2F',
searchParams: URLSearchParams { 'callbackUrl' => 'http://localhost:3000/' },
hash: ''
}
url URL {
href: 'https://localhost:3000/api/auth/providers',
origin: 'https://localhost:3000',
protocol: 'https:',
username: '',
password: '',
host: 'localhost:3000',
hostname: 'localhost',
port: '3000',
pathname: '/api/auth/providers',
search: '',
searchParams: URLSearchParams {},
hash: ''
}
[nuxt] [request error] [unhandled] [500] Cannot set headers after they are sent to the client
at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
at new NodeError (node:internal/errors:405:5)
at ServerResponse.setHeader (node:_http_outgoing:648:11)
at setResponseHeaders (./node_modules/h3/dist/index.mjs:778:20)
at Object.handler (./node_modules/nitropack/dist/runtime/renderer.mjs:31:7)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.handler (./node_modules/h3/dist/index.mjs:1962:19)
at async Server.toNodeHandle (./node_modules/h3/dist/index.mjs:2249:7)
url URL {
href: 'https://localhost:3000/login',
origin: 'https://localhost:3000',
protocol: 'https:',
username: '',
password: '',
host: 'localhost:3000',
hostname: 'localhost',
port: '3000',
pathname: '/login',
search: '',
searchParams: URLSearchParams {},
hash: ''
}
url URL {
href: 'https://localhost:3000/api/auth/session?callbackUrl=http:%2F%2Flocalhost:3000%2Flogin',
origin: 'https://localhost:3000',
protocol: 'https:',
username: '',
password: '',
host: 'localhost:3000',
hostname: 'localhost',
port: '3000',
pathname: '/api/auth/session',
search: '?callbackUrl=http:%2F%2Flocalhost:3000%2Flogin',
searchParams: URLSearchParams { 'callbackUrl' => 'http://localhost:3000/login' },
hash: ''
}
" during these calls, I am having an error which you can see. Can you suggest me how to resolve it.
Additional context
I am using nuxt3 for nuxt-auth integration.
Logs
No response
The text was updated successfully, but these errors were encountered: