I am encountering an issue with my Express.js application when trying to integrate Auth.js. The API starts up fine, but when navigating beyond /api/auth, I receive a stack trace error without any logs in the console. Additionally, it redirects to /api/auth/error?error=Configuration
[auth][error] TypeError: (0 , import_preact_render_to_string.renderToString) is not a function
api:dev:at send (/Users/josh/projects/saas-starter-kit/node_modules/@auth/core/lib/pages/index.js:13:350)
api:dev:at Object.error (/Users/josh/projects/saas-starter-kit/node_modules/@auth/core/lib/pages/index.js:119:20)
api:dev:at AuthInternal (/Users/josh/projects/saas-starter-kit/node_modules/@auth/core/lib/index.js:31:31)
api:dev:at Auth (/Users/josh/projects/saas-starter-kit/node_modules/@auth/core/index.js:109:34)
api:dev:at <anonymous> (/Users/josh/projects/saas-starter-kit/node_modules/@auth/express/index.js:141:45)
Steps to reproduce:
tsconfig.json
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"outDir": "./dist",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
index.ts
import { logger } from '@repo/logger'
import 'dotenv/config'
import { createServer } from './server'
const port = process.env.PORT || 3001
const server = createServer()
server.listen(port, async() => {
logger.info(`api server is starting: Date: ${new Date()}`)
})
server.ts
import express, { type Express } from 'express'
import morgan from 'morgan'
import { ExpressAuth } from "@auth/express"
import GitHub from "@auth/express/providers/github"
export const createServer = (): Express => {
const app = express()
app
.use(express.urlencoded({ extended: true }))
.use(express.json())
.set("trust proxy", true)
.use("/api/auth/*", ExpressAuth({
debug: true,
trustHost: true,
providers: [
GitHub
],
}))
.get('/status', (_, res) => {
return res.json({ ok: true })
})
return app
}
.env.local
AUTH_SECRET=""
AUTH_GITHUB_ID=""
AUTH_GITHUB_SECRET=""
AUTH_URL="http://localhost:3001/api/auth"
Command to start up
dotenvx run --env-file ./.env.local -- nodemon --exec \"node -r esbuild-register ./src/index.ts\" -e .ts
Expected behavior: I expected the signin page to load successfully instead of receiving a server console error message.