Open
Description
Adapter type
@auth/typeorm-adapter
Environment
System:
OS: Linux 6.13 Fedora Linux 41 (KDE Plasma)
CPU: (24) x64 AMD Ryzen 9 9900X 12-Core Processor
Memory: 94.10 GB / 123.46 GB
Container: Yes
Shell: 5.2.32 - /bin/bash
Binaries:
Node: 23.9.0 - ~/.proto/shims/node
Yarn: 4.6.0 - ~/.proto/shims/yarn
npm: 10.9.2 - /usr/bin/npm
pnpm: 10.7.1 - ~/.proto/shims/pnpm
Browsers:
Chrome: 135.0.7049.52
Reproduction URL
https://github.com/a-h-i/next-typeorm-minimalexample
Describe the issue
I have setup the next app auth.ts like so
import NextAuth from 'next-auth';
import SendGrid from 'next-auth/providers/sendgrid';
import { TypeORMAdapter } from '@auth/typeorm-adapter';
export const { handlers, signIn, signOut, auth } = NextAuth({
providers: [SendGrid({
from: '[email protected]',
})],
adapter: TypeORMAdapter({
type: 'postgres',
host: process.env.PG_MASTER_HOST!,
port: parseInt(process.env.PG_MASTER_PORT!, 10),
username: process.env.PG_USER!,
password: process.env.PG_PASSWORD!,
database: process.env.PG_DB!,
synchronize: true,
}),
callbacks: {
authorized: async ({ auth }) => {
// Logged in users are authenticated, otherwise redirect to login page
return !!auth
},
signIn({ user }) {
return !!user.email?.endsWith('@refound.com');
},
},
debug: true
});
When signing in the magic link is sent to my email and a verification record is inserted into the db, however when I follow the link in the email I get the following error.
[auth][error] SessionTokenError: Read more at https://errors.authjs.dev#sessiontokenerror
[auth][cause]: TypeError: Cannot read properties of undefined (reading 'type')
at EntityManagerFactory.create (/home/ahi/WebstormProjects/satori_nextjs/apps/admin/.next/server/edge/chunks/1459c_typeorm_browser_86bd9157._.js:6898:39)
at DataSource.createEntityManager (/home/ahi/WebstormProjects/satori_nextjs/apps/admin/.next/server/edge/chunks/1459c_typeorm_browser_86bd9157._.js:9093:443)
at new DataSource (/home/ahi/WebstormProjects/satori_nextjs/apps/admin/.next/server/edge/chunks/1459c_typeorm_browser_86bd9157._.js:8802:29)
at getManager (/home/ahi/WebstormProjects/satori_nextjs/apps/admin/.next/server/edge/chunks/node_modules__pnpm_c519da07._.js:9962:23)
at getSessionAndUser (/home/ahi/WebstormProjects/satori_nextjs/apps/admin/.next/server/edge/chunks/node_modules__pnpm_c519da07._.js:10075:29)
at acc.<computed> (/home/ahi/WebstormProjects/satori_nextjs/apps/admin/.next/server/edge/chunks/c1962_@auth_core_a0c6e6aa._.js:1364:30)
at session (/home/ahi/WebstormProjects/satori_nextjs/apps/admin/.next/server/edge/chunks/c1962_@auth_core_a0c6e6aa._.js:4301:36)
at AuthInternal (/home/ahi/WebstormProjects/satori_nextjs/apps/admin/.next/server/edge/chunks/c1962_@auth_core_a0c6e6aa._.js:4838:269)
at async Auth (/home/ahi/WebstormProjects/satori_nextjs/apps/admin/.next/server/edge/chunks/c1962_@auth_core_a0c6e6aa._.js:5091:34)
at async handleAuth (/home/ahi/WebstormProjects/satori_nextjs/apps/admin/.next/server/edge/chunks/node_modules__pnpm_c519da07._.js:3918:29)
[auth][details]: {}
How to reproduce
Request a magic link then follow it from your email
Expected behavior
The db connection to work