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
feat(adapter-drizzle): add option to pass in schema #8561
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
@juliusmarminge is attempting to deploy a commit to the authjs Team on Vercel. A member of the Team first needs to authorize it. |
packages/adapter-drizzle/tests/mysql-custom-tables/schema.ts
Dismissed
Show dismissed
Hide dismissed
Following the workaround in the first comment until the Drizzle adapter supports custom tables. import { type InferSelectModel } from "drizzle-orm";
import { users } from "@/server/db/schema";
declare module "@auth/core/adapters" {
interface AdapterUser extends InferSelectModel<typeof users> {
// ...other properties
document: string | null;
}
} |
This is quite an essential feature when you want to add roles to a user. The workaround works for retrieving them. But if you want to store extra fields you also have to override the correct write functions. So yes 👍🏻 |
Can't wait for this to be implemented. Spent hours figuring out why some profile data wasn't being inserted into my custom fields 🤦♂️ |
Sorry for the ping @balazsorban44, but could we get some eyes on this? |
+1 on this one, was confused as to why my additional columns on my |
fa96b45
to
65aa467
Compare
man why is this not merged yet :( |
This similar PR adds support for custom table naming schema and a custom |
@ndom91 looks like you're a codeowner, anything blocking this PR from going through? Happy to help fix anything if necessary |
BTW, one potential issue with this PR:
assumes that the table name is |
For anyone having a similar issue, you can use you own table definitions like this:
I'm sorry for the |
☕️ Reasoning
In other adapters, the adapter returns the entire table so if you have additional fields they will also be returned when the adapter queries the table. A good example here is if your user tables contains an additional field
defaultCurrency
, this "should" be returned from the adapter.With drizzle, this isn't the case since the adapter is using it's own tables. This means additional fields aren't returned. This PR aims to provide an API to allow the user to pass custom tables to the adapter which will make it so the entire table is returned by the adapter and can be used in callbacks to create a session object containing the additional field(s).
I've made the changes so that they are backwards compatible. The downside to this is that if you're using custom table fn, you'll need to pass in all the tables to the object, and not just the table you have custom fields in. A perhaps better API would be
but that would require a breaking change, which might be okay given the adapter is still at a
0.x
version? What do you think @balazsorban44 ?My current "workaround" is to override the
getUserAndSession
function to use my own table, but would be nicer to have this work ootb🧢 Checklist
🎫 Affected issues
Please scout and link issues that might be solved by this PR.
Fixes: INSERT_ISSUE_LINK_HERE
📌 Resources