mongodb id map and gen for prisma issue #103

Closed
opened 2026-03-13 07:33:33 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @csyedbilal on GitHub (Oct 19, 2024).

@Bekacru
[{
"resource": "/B:/with-better-auth/prisma/schema.prisma",
"owner": "generated_diagnostic_collection_name#0",
"severity": 8,
"message": "Error validating field user in model Session: The relation field user on model Session is missing an opposite relation field on the model User. Either run prisma format or add it manually.",
"source": "Prisma",
"startLineNumber": 35,
"startColumn": 3,
"endLineNumber": 36,
"endColumn": 1
},{
"resource": "/B:/with-better-auth/prisma/schema.prisma",
"owner": "generated_diagnostic_collection_name#0",
"severity": 8,
"message": "Error validating field user in model Account: The relation field user on model Account is missing an opposite relation field on the model User. Either run prisma format or add it manually.",
"source": "Prisma",
"startLineNumber": 45,
"startColumn": 3,
"endLineNumber": 46,
"endColumn": 1
}]

"better-auth": "^0.5.2-beta.2",
"@better-auth/cli": "^0.5.2-beta.2",

image

Originally posted by @csyedbilal in https://github.com/better-auth/better-auth/issues/215#issuecomment-2423842942

Originally created by @csyedbilal on GitHub (Oct 19, 2024). @Bekacru [{ "resource": "/B:/with-better-auth/prisma/schema.prisma", "owner": "_generated_diagnostic_collection_name_#0", "severity": 8, "message": "Error validating field `user` in model `Session`: The relation field `user` on model `Session` is missing an opposite relation field on the model `User`. Either run `prisma format` or add it manually.", "source": "Prisma", "startLineNumber": 35, "startColumn": 3, "endLineNumber": 36, "endColumn": 1 },{ "resource": "/B:/with-better-auth/prisma/schema.prisma", "owner": "_generated_diagnostic_collection_name_#0", "severity": 8, "message": "Error validating field `user` in model `Account`: The relation field `user` on model `Account` is missing an opposite relation field on the model `User`. Either run `prisma format` or add it manually.", "source": "Prisma", "startLineNumber": 45, "startColumn": 3, "endLineNumber": 46, "endColumn": 1 }] "better-auth": "^0.5.2-beta.2", "@better-auth/cli": "^0.5.2-beta.2", ![image](https://github.com/user-attachments/assets/5b50434b-ba98-4f13-969d-068a9995c744) _Originally posted by @csyedbilal in https://github.com/better-auth/better-auth/issues/215#issuecomment-2423842942_
Author
Owner

@Bekacru commented on GitHub (Oct 19, 2024):

you just need to save it and it'll get formatted properly.

@Bekacru commented on GitHub (Oct 19, 2024): you just need to save it and it'll get formatted properly.
Author
Owner

@Bekacru commented on GitHub (Oct 19, 2024):

if you have format on save

@Bekacru commented on GitHub (Oct 19, 2024): if you have format on save
Author
Owner

@csyedbilal commented on GitHub (Oct 19, 2024):

@Bekacru i have updated the Prisma schema to resolve the issues.

Here are the changes made:
In the User model, I added two new fields:

sessions Session[]: This creates a one-to-many relationship between User and Session.
accounts Account[]: This creates a one-to-many relationship between User and Account.

B:\with-better-auth>bunx prisma db push
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": MongoDB database "test" at "127.0.0.1:27017"
Applying the following changes:

[+] Collection user
[+] Collection session
[+] Collection account
[+] Collection verification
[+] Unique index user_email_key on ({"email":1})

Your database indexes are now in sync with your Prisma schema. Done in 157ms

✔ Generated Prisma Client (v5.21.1) to .\node_modules@prisma\client in 126ms

another issues

✓ Compiled / in 13.8s
GET / 200 in 14552ms
○ Compiling /api/auth/[...all] ...
✓ Compiled /api/auth/[...all] in 2.7s
GET /api/auth/csrf 200 in 4587ms
POST /api/auth/sign-in/social?currentURL=http%3A%2F%2Flocalhost%3A3000%2F 200 in 234ms
PrismaClientKnownRequestError:
Invalid a[e].create() invocation in
B:\huc-projects\with-better-auth.next\server\chunks\node_modules_better-auth_dist_003810._.js:3055:74

3052 id: "prisma",
3053 async create (t) {
3054 let { model: e, data: n, select: r } = t;
→ 3055 return i !== void 0 && (n.id = i ? i() : void 0), await a[e].create(
Prisma needs to perform transactions, which requires your MongoDB server to be run as a replica set. https://pris.ly/d/mongodb-replica-set
at Mn.handleRequestError (B:\with-better-auth\node_modules@prisma\client\runtime\library.js:121:7753)
at Mn.handleAndLogRequestError (B:\huc-projects\with-better-auth\node_modules@prisma\client\runtime\library.js:121:7061)
at Mn.request (B:\with-better-auth\node_modules@prisma\client\runtime\library.js:121:6745)
at async l (B:\huc-projects\with-better-auth\node_modules@prisma\client\runtime\library.js:130:9633)
at async Object.create (B:\with-better-auth.next\server\chunks\node_modules_better-auth_dist_003810..js:3055:63)
at async s (B:\huc-projects\with-better-auth.next\server\chunks\node_modules_better-auth_dist_003810.
.js:2468:71)
at async Object.createOAuthUser (B:\huc-projects\with-better-auth.next\server\chunks\node_modules_better-auth_dist_003810..js:2512:25)
at async B:\with-better-auth.next\server\chunks\node_modules_better-auth_dist_003810.
.js:1333:38
at async handle (B:\with-better-auth.next\server\chunks\node_modules_81e739..js:878:23)
at async a. (B:\with-better-auth.next\server\chunks\node_modules_better-auth_dist_003810.
.js:2028:17)
at async handler (B:\with-better-auth.next\server\chunks\node_modules_81e739..js:1086:32)
at async handler (B:\with-better-auth.next\server\chunks\node_modules_81e739.
.js:1137:25)
at async B:\with-better-auth\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:63352
at async eP.execute (B:\with-better-auth\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:54549)
at async eP.handle (B:\huc-projects\with-better-auth\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:64693)
at async doRender (B:\huc-projects\with-better-auth\node_modules\next\dist\server\base-server.js:1419:42)
at async responseGenerator (B:\huc-projects\with-better-auth\node_modules\next\dist\server\base-server.js:1640:40)
at async DevServer.renderToResponseWithComponentsImpl (B:\huc-projects\with-better-auth\node_modules\next\dist\server\base-server.js:1665:28)
at async DevServer.renderPageComponent (B:\huc-projects\with-better-auth\node_modules\next\dist\server\base-server.js:1978:24)
at async DevServer.renderToResponseImpl (B:\huc-projects\with-better-auth\node_modules\next\dist\server\base-server.js:2016:32)
at async DevServer.pipeImpl (B:\huc-projects\with-better-auth\node_modules\next\dist\server\base-server.js:908:25)
at async NextNodeServer.handleCatchallRenderRequest (B:\huc-projects\with-better-auth\node_modules\next\dist\server\next-server.js:273:17)
at async DevServer.handleRequestImpl (B:\huc-projects\with-better-auth\node_modules\next\dist\server\base-server.js:804:17)
at async B:\huc-projects\with-better-auth\node_modules\next\dist\server\dev\next-dev-server.js:339:20
at async Span.traceAsyncFn (B:\huc-projects\with-better-auth\node_modules\next\dist\trace\trace.js:157:20)
at async DevServer.handleRequest (B:\huc-projects\with-better-auth\node_modules\next\dist\server\dev\next-dev-server.js:336:24)
at async invokeRender (B:\huc-projects\with-better-auth\node_modules\next\dist\server\lib\router-server.js:175:21)
at async handleRequest (B:\huc-projects\with-better-auth\node_modules\next\dist\server\lib\router-server.js:354:24)
at async requestHandlerImpl (B:\huc-projects\with-better-auth\node_modules\next\dist\server\lib\router-server.js:378:13)
at async Server.requestListener (B:\huc-projects\with-better-auth\node_modules\next\dist\server\lib\start-server.js:142:13) {
code: 'P2031',
clientVersion: '5.21.1',
meta: { modelName: 'User' }
}
GET /api/auth/callback/github?code=59b5e4916404808a5f55&state=%7B%22code%22%3A%22Ukx40IWDzFboBcV-Uz1Avi6A9EG5lToralY1jyJUQNc%22%2C%22callbackURL%22%3A%22http%3A%2F%2Flocalhost%3A3000%22%7D 302 in 1426ms
GET /?error=unable_to_create_session 200 in 365ms

@csyedbilal commented on GitHub (Oct 19, 2024): @Bekacru i have updated the Prisma schema to resolve the issues. Here are the changes made: In the User model, I added two new fields: sessions Session[]: This creates a one-to-many relationship between User and Session. accounts Account[]: This creates a one-to-many relationship between User and Account. B:\with-better-auth>bunx prisma db push Environment variables loaded from .env Prisma schema loaded from prisma\schema.prisma Datasource "db": MongoDB database "test" at "127.0.0.1:27017" Applying the following changes: [+] Collection `user` [+] Collection `session` [+] Collection `account` [+] Collection `verification` [+] Unique index `user_email_key` on ({"email":1}) Your database indexes are now in sync with your Prisma schema. Done in 157ms ✔ Generated Prisma Client (v5.21.1) to .\node_modules\@prisma\client in 126ms another issues ✓ Compiled / in 13.8s GET / 200 in 14552ms ○ Compiling /api/auth/[...all] ... ✓ Compiled /api/auth/[...all] in 2.7s GET /api/auth/csrf 200 in 4587ms POST /api/auth/sign-in/social?currentURL=http%3A%2F%2Flocalhost%3A3000%2F 200 in 234ms PrismaClientKnownRequestError: Invalid `a[e].create()` invocation in B:\huc-projects\with-better-auth\.next\server\chunks\node_modules_better-auth_dist_003810._.js:3055:74 3052 id: "prisma", 3053 async create (t) { 3054 let { model: e, data: n, select: r } = t; → 3055 return i !== void 0 && (n.id = i ? i() : void 0), await a[e].create( Prisma needs to perform transactions, which requires your MongoDB server to be run as a replica set. https://pris.ly/d/mongodb-replica-set at Mn.handleRequestError (B:\with-better-auth\node_modules\@prisma\client\runtime\library.js:121:7753) at Mn.handleAndLogRequestError (B:\huc-projects\with-better-auth\node_modules\@prisma\client\runtime\library.js:121:7061) at Mn.request (B:\with-better-auth\node_modules\@prisma\client\runtime\library.js:121:6745) at async l (B:\huc-projects\with-better-auth\node_modules\@prisma\client\runtime\library.js:130:9633) at async Object.create (B:\with-better-auth\.next\server\chunks\node_modules_better-auth_dist_003810._.js:3055:63) at async s (B:\huc-projects\with-better-auth\.next\server\chunks\node_modules_better-auth_dist_003810._.js:2468:71) at async Object.createOAuthUser (B:\huc-projects\with-better-auth\.next\server\chunks\node_modules_better-auth_dist_003810._.js:2512:25) at async B:\with-better-auth\.next\server\chunks\node_modules_better-auth_dist_003810._.js:1333:38 at async handle (B:\with-better-auth\.next\server\chunks\node_modules_81e739._.js:878:23) at async a.<computed> (B:\with-better-auth\.next\server\chunks\node_modules_better-auth_dist_003810._.js:2028:17) at async handler (B:\with-better-auth\.next\server\chunks\node_modules_81e739._.js:1086:32) at async handler (B:\with-better-auth\.next\server\chunks\node_modules_81e739._.js:1137:25) at async B:\with-better-auth\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:63352 at async eP.execute (B:\with-better-auth\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:54549) at async eP.handle (B:\huc-projects\with-better-auth\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:64693) at async doRender (B:\huc-projects\with-better-auth\node_modules\next\dist\server\base-server.js:1419:42) at async responseGenerator (B:\huc-projects\with-better-auth\node_modules\next\dist\server\base-server.js:1640:40) at async DevServer.renderToResponseWithComponentsImpl (B:\huc-projects\with-better-auth\node_modules\next\dist\server\base-server.js:1665:28) at async DevServer.renderPageComponent (B:\huc-projects\with-better-auth\node_modules\next\dist\server\base-server.js:1978:24) at async DevServer.renderToResponseImpl (B:\huc-projects\with-better-auth\node_modules\next\dist\server\base-server.js:2016:32) at async DevServer.pipeImpl (B:\huc-projects\with-better-auth\node_modules\next\dist\server\base-server.js:908:25) at async NextNodeServer.handleCatchallRenderRequest (B:\huc-projects\with-better-auth\node_modules\next\dist\server\next-server.js:273:17) at async DevServer.handleRequestImpl (B:\huc-projects\with-better-auth\node_modules\next\dist\server\base-server.js:804:17) at async B:\huc-projects\with-better-auth\node_modules\next\dist\server\dev\next-dev-server.js:339:20 at async Span.traceAsyncFn (B:\huc-projects\with-better-auth\node_modules\next\dist\trace\trace.js:157:20) at async DevServer.handleRequest (B:\huc-projects\with-better-auth\node_modules\next\dist\server\dev\next-dev-server.js:336:24) at async invokeRender (B:\huc-projects\with-better-auth\node_modules\next\dist\server\lib\router-server.js:175:21) at async handleRequest (B:\huc-projects\with-better-auth\node_modules\next\dist\server\lib\router-server.js:354:24) at async requestHandlerImpl (B:\huc-projects\with-better-auth\node_modules\next\dist\server\lib\router-server.js:378:13) at async Server.requestListener (B:\huc-projects\with-better-auth\node_modules\next\dist\server\lib\start-server.js:142:13) { code: 'P2031', clientVersion: '5.21.1', meta: { modelName: 'User' } } GET /api/auth/callback/github?code=59b5e4916404808a5f55&state=%7B%22code%22%3A%22Ukx40IWDzFboBcV-Uz1Avi6A9EG5lToralY1jyJUQNc%22%2C%22callbackURL%22%3A%22http%3A%2F%2Flocalhost%3A3000%22%7D 302 in 1426ms GET /?error=unable_to_create_session 200 in 365ms
Author
Owner

@Bekacru commented on GitHub (Oct 20, 2024):

I don't think this issue is related to Better Auth. Can you explain why you think this is an issue with Better Auth rather than a Prisma issue?

@Bekacru commented on GitHub (Oct 20, 2024): I don't think this issue is related to Better Auth. Can you explain why you think this is an issue with Better Auth rather than a Prisma issue?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#103