BA
Better Auth2mo ago
wz

Can I Add a User-Type Condition to the SQL WHERE Clause During Sign-in?

I have added a "role" field to the user model as follows. Is it possible to add a condition to the SQL WHERE clause to only include users with a specific "role" when signing in? I have looked through the documentation and source code, but I couldn't find a way to extend the SELECT conditions. Please let me know if there is a good way to do this.
export const auth = betterAuth({
user: {
additionalFields: {
role: {
type: "string",
required: true,
},
},
},
})
export const auth = betterAuth({
user: {
additionalFields: {
role: {
type: "string",
required: true,
},
},
},
})
Is there a way to write and execute it like this?
auth.api.signInEmail({
body: {
email: email,
password: password,
role: "roleA",
},
});
auth.api.signInEmail({
body: {
email: email,
password: password,
role: "roleA",
},
});
2 Replies
bekacru
bekacru2mo ago
that's not possible but you can check if the user has that role after auth.api responds. You can also use hooks to avoid making additional db query.
wz
wzOP2mo ago
Thanks. It looks like I can access roles.

Did you find this page helpful?