nextauthjs / nextauthjs/next-auth

FaunaAdapter : create_User fails because of native id constraints

Open
#12,234 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

adapters bug triage
Dominant language
TypeScript
Stars
28.4k
Forks
4k
PR merge metrics
No merged PRs in 30d

Description

Adapter type

@auth/fauna-adapter

Environment

System:
OS: macOS 14.5
CPU: (8) arm64 Apple M2
Memory: 137.31 MB / 8.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.12.1 - ~/.nvm/versions/node/v20.12.1/bin/node
npm: 10.5.0 - ~/.nvm/versions/node/v20.12.1/bin/npm
Browsers:
Safari: 17.5
npmPackages:
@auth/fauna-adapter: ^3.7.3 => 3.7.3
next: 15.0.3 => 15.0.3
next-auth: ^5.0.0-beta.25 => 5.0.0-beta.25
react: 19.0.0-rc-66855b96-20241106 => 19.0.0-rc-66855b96-20241106

Reproduction URL

https://github.com/SB17Codes/faunaadapter-error.git

Describe the issue

I'm developing a web application using Next.js and implementing an authentication system with NextAuth.js and FaunaDB through the Fauna adapter. Despite following the official documentation for both NextAuth and the Fauna adapter, I'm encountering a critical error during the user authentication process.

adapter_createUser {
  "args": [
    {
      "id": "540bc67d-4e79-4b25-test",
      "name": "tes",
      "email": "test@gmail.com",
      "image": "https://lh3.googleusercontent.com/a/test=s96-c",
      "emailVerified": null
    }
  ]
}
[auth][error] AdapterError: Read more at https://errors.authjs.dev#adaptererror
[auth][cause]: ConstraintFailureError: Failed to create document in collection `User`.
[auth][details]: {}
[auth][error] AdapterError: Read more at https://errors.authjs.dev#adaptererror
[auth][cause]: ConstraintFailureError: Failed to create document in collection `User`.
[auth][details]: {}
[auth][error] AdapterError: Read more at https://errors.authjs.dev#adaptererror
[auth][cause]: ConstraintFailureError: Failed to create document in collection `User`.
[auth][details]: {}
[auth][error] AdapterError: Read more at https://errors.authjs.dev#adaptererror
[auth][cause]: ConstraintFailureError: Failed to create document in collection `User`.
[auth][details]: {}

I've followed the documentation for the FaunaAdapter to the letter created the schemas for the necessary tables as indicated but after trying to debug the issue using the Fauna Dashboard I noticed that the id field is a reserved field in fauna but still we could create User documents using custom ids that we provide up to a certain length and then it would give us the following error:

User.create({
  id: "111111111111111111111111111111"
})

constraint_failure

error: Failed to create document in collection `User`.
constraint failures:
  id: Expected ID | String | Long, provided String
at *query*:1:12
  |
1 |   User.create({
  |  ____________^
2 | |   id: "111111111111111111111111111111"
3 | | })
  | |__^
  |

and since the id that the social providers return is usually a too long the create_User function from the adapter returns constraint error related to the id

How to reproduce

Set up the .env.local with the appropriate variables from FaunaDB and google OAuth app and run the application

Expected behavior

Create a User in the fauna database

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked reproduction repository and the @auth/fauna-adapter create_User path, then compare the provider-supplied id with Fauna's documented constraints. Reproduce the failure using the supplied environment and OAuth setup; done means authentication creates a User without a constraint_failure error.

Written by the indexing model from the issue text.

Assessment

Tech stack
nextjs, nodejs, typescript
Domain
authentication, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.