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

getting cannot read properties of undefined (reading 'type') #12854

Open
a-h-i opened this issue Apr 7, 2025 · 0 comments
Open

getting cannot read properties of undefined (reading 'type') #12854

a-h-i opened this issue Apr 7, 2025 · 0 comments
Labels
adapters Changes related to the core code concerning database adapters bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@a-h-i
Copy link

a-h-i commented Apr 7, 2025

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

@a-h-i a-h-i added adapters Changes related to the core code concerning database adapters bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Apr 7, 2025
@a-h-i a-h-i changed the title etting cannot read properties of undefined (reading 'type') getting cannot read properties of undefined (reading 'type') Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adapters Changes related to the core code concerning database adapters bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

No branches or pull requests

1 participant