nextauthjs / next-auth

Authentication for the Web.
https://authjs.dev
ISC License
25.03k stars 3.54k forks source link

FaunaAdapter : create_User fails because of native id constraints #12234

Open SB17Codes opened 1 week ago

SB17Codes commented 1 week ago

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