#After I upgraded to NextJS 14/13.5 from 13.4 next-auth is failing

3 messages · Page 1 of 1 (latest)

arctic pelican
#

I tried to get an answer to this issue for weeks already and didn't manage to get any help.

After I upgraded to NextJS 13.5/14 from 13.4 I started to get this error each time I'm trying to login. I'm using next-auth with TypeORM-Adapter connected to PostgreSQL. The strange thing about it, is that I only get this error in production mode and not in development mode.

[next-auth][error][adapter_error_getSessionAndUser] 
https://next-auth.js.org/errors#adapter_error_getsessionanduser No metadata for "SessionEntity" was found. {
  message: 'No metadata for "SessionEntity" was found.',
  stack: 'EntityMetadataNotFoundError: No metadata for "SessionEntity" was found.\n' +
    '    at t.DataSource.getMetadata (/home/guy/workspace/falkordb-cloud/.next/server/chunks/871.js:52:45111)\n' +
    '    at t.EntityManager.findOne (/home/guy/workspace/falkordb-cloud/.next/server/chunks/871.js:149:25750)\n' +
    '    at getSessionAndUser (/home/guy/workspace/falkordb-cloud/.next/server/chunks/871.js:150:415819)\n' +
    '    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)',
  name: 'EntityMetadataNotFoundError'
}

I tried to play with the code, but I couldn't find a solution it seems like something has changed in the way nextjs is building the code in 13.5/14

Published on stackoverflow
https://stackoverflow.com/questions/77348457/error-https-next-auth-js-org-errorsadapter-error-getsessionanduser-no-metada

On next-auth repo
https://github.com/nextauthjs/next-auth/issues/8822

GitHub

Environment System: OS: Linux 6.2 Ubuntu 23.04 23.04 (Lunar Lobster) CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz Memory: 5.44 GB / 31.06 GB Container: Yes Shell: 5.2.15 - /bin/bash ...

upper tundraBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

arctic pelican
#

I found the issue:
If the application redefine the entities used by the TypeORM-Adapter (like I do)
As explained in https://authjs.dev/reference/adapter/typeorm#advanced-usage

After Next 13.5 it seems like Next is shortening the classnames in build time, e.g. from AccountEntity to a
The problem is that TypeORM is using the classname by default for the class lookup.
The solution is to set the classname in the decorator
e.g.

@Entity("AccountEntity", { name: "accounts" })
export class AccountEntity {

Official TypeORM adapter for Auth.js / NextAuth.js.