next-auth icon indicating copy to clipboard operation
next-auth copied to clipboard

feat: add options object where you can specify a schema

Open jlvdh opened this issue 1 year ago • 5 comments

☕️ Reasoning

The @auth/kysely-adapter currently depends on the tables to be configured in postgres. But it's good practice to add the tables in their own schema (eg auth.User, auth.Session, etc.) This PR would enable the configuration of a schema that is used for all the necessary tables by using: KyselyAdapter(db, {schemaName: "auth"})

Interested to hear if this type of feature would be eligible to merge in the project?

🧢 Checklist

  • [x] Documentation
  • [x] Tests
  • [x] Ready to be merged

jlvdh avatar Jul 07 '24 10:07 jlvdh

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

Name Status Preview Comments Updated (UTC)
auth-docs ❌ Failed (Inspect) Aug 9, 2024 9:25am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
next-auth-docs ⬜️ Ignored (Inspect) Visit Preview Aug 9, 2024 9:25am

vercel[bot] avatar Jul 07 '24 10:07 vercel[bot]

@jlvdh is attempting to deploy a commit to the authjs Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Jul 07 '24 10:07 vercel[bot]

Yeah so in general we do something similar in most other adapters. Ideally we wouldn't have an implicit link between what you name something in your DB schema manually adn the name we expect in the kysely adapter code..

I'm not familiar with Kysely, but can you explicitly define the schemas and pass them to the Kysely instance? Like we do in the Drizzle adapter

ndom91 avatar Jul 21 '24 09:07 ndom91

@ndom91 Thanks for the reply.

Kysely doesn't seem to use models like Drizzle. In Kysely you write your own migrations. So passing the schema and table names would be in string format.

KyselyAdapter(db, {schemaName: "auth"})

Could simply be added using withSchema

ie: https://github.com/nextauthjs/next-auth/pull/11344/files#diff-8f2587157000f269c1784f539508271ebb924ca9b7f5a5fdccd02fe2682c56e5R70

For further customisation of the table names we could do something like:

KyselyAdapter(db, {schemaName: "auth", accountTable: "account", userTable: "user" .. etc })

jlvdh avatar Jul 22 '24 16:07 jlvdh

Added tests and docs now too

jlvdh avatar Aug 09 '24 09:08 jlvdh

It looks like this issue did not receive any activity for 60 days. It will be closed in 7 days if no further activity occurs. If you think your issue is still relevant, commenting will keep it open. Thanks!

stale[bot] avatar Jan 21 '25 23:01 stale[bot]

To keep things tidy, we are closing this issue for now. If you think your issue is still relevant, leave a comment and we might reopen it. Thanks!

stale[bot] avatar Jan 31 '25 23:01 stale[bot]