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

fix(dgraph): id generation overlap #10719

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

korzhanov
Copy link

@korzhanov korzhanov commented Apr 24, 2024

☕️ Reasoning

Dgraph will generate the ID by itself. In Dgraph, every node has a unique 64-bit identifier that you can expose in GraphQL using the ID type. An ID is auto-generated, immutable and never reused. Each type can have at most one ID field.

The ID type works great when you need to use an identifier on nodes and don’t need to set that identifier externally
DGraph type docs

Since next-auth.js or auth.js creates a new user id, this causes an error and does not save the entry to dgraph

🧢 Checklist

  • Documentation
  • Tests
  • Ready to be merged

🎫 Affected issues

📌 Resources

Dgraph will generate the ID by itself. In Dgraph, every node has a unique 64-bit identifier that you can expose in GraphQL using the ID type. An ID is auto-generated, immutable and never reused. Each type can have at most one ID field.

The ID type works great when you need to use an identifier on nodes and don’t need to set that identifier externally
@korzhanov korzhanov requested a review from ndom91 as a code owner April 24, 2024 21:23
Copy link

vercel bot commented Apr 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
auth-docs ❌ Failed (Inspect) Apr 24, 2024 9:24pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
next-auth-docs ⬜️ Ignored (Inspect) Visit Preview Apr 24, 2024 9:24pm

@github-actions github-actions bot added adapters Changes related to the core code concerning database adapters dgraph @auth/dgraph-adapter labels Apr 24, 2024
@ndom91 ndom91 changed the title Fix createUser at DGraph Adapter fix(dgraph): id generation overlap Apr 28, 2024
@ndom91
Copy link
Member

ndom91 commented Apr 28, 2024

Just curious why the current tests pass and why this isn't necessary for createSession or createVerificationToken, for example, then? 🤔

@korzhanov
Copy link
Author

@ndom91 Sorry, I didn't see your comment in this thread without mention.

Just curious why the current tests pass and why this isn't necessary for createSession or createVerificationToken, for example, then? 🤔

The test uses a predefined id value id: () => "0x0a0a00a00" that falls under the DGraph requirements.

runBasicTests({
adapter: DgraphAdapter(params),
db: {
id: () => "0x0a0a00a00",
async disconnect() {
await c.run(/* GraphQL */ `
mutation {
deleteUser(filter: {}) {
numUids
}
deleteVerificationToken(filter: {}) {
numUids
}
deleteSession(filter: {}) {
numUids
}
deleteAccount(filter: {}) {
numUids
}
}
`)
},

And in reality, the random UUID is invalid, it doesn't match the DGraph UID conditions.

Situation similar to the FaunaDB adapter

runBasicTests({
adapter: FaunaAdapter(client),
db: {
// UUID is not a valid ID in Fauna (see https://docs.fauna.com/fauna/current/reference/fql_reference/types#id)
id: () => String(Math.floor(Math.random() * 10 ** 18)),
user: async (id) => {
const response = await client.query<FaunaUser>(fql`User.byId(${id})`)
if (response.data instanceof NullDocument) return null
return format.from(response.data)
},

And I think maybe createSession and createVerificationToken don't use external generated ids, only internal ones

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 dgraph @auth/dgraph-adapter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants