Augustas Paliulis
Augustas Paliulis
BABetter Auth
Created by Augustas Paliulis on 2/23/2025 in #help
Integrate new table schema created using plugin with authentication
Hello, I have created new table schema using plugin, and now I would like to integrate and populate that table during authentication. It might be the cas that I haven't seen required documentation on that, so link to that could also help. Basically I have this TermsOfService table plugin:
const tosPlugin = () => {
return {
id: 'tos-plugin',
schema: {
TermsOfService: {
fields: {
...
const tosPlugin = () => {
return {
id: 'tos-plugin',
schema: {
TermsOfService: {
fields: {
...
and I have inserted this plugin in config:
export const auth = betterAuth({
...
plugins: [tosPlugin(), privacyPolicyPlugin()],
});
export const auth = betterAuth({
...
plugins: [tosPlugin(), privacyPolicyPlugin()],
});
Should I create hook for populating that table? If so should I create connection myself, or is there a way to do this using better-auth. Thanks!
2 replies
BABetter Auth
Created by Augustas Paliulis on 2/23/2025 in #bug-reports
Typescript error on plugin schema reference field
When creating plugin for table schema, and adding reference to another table (e.g. user) I get TS error that instaed of reference it should be references
Object literal may only specify known properties, but 'reference' does not exist in type 'FieldAttribute<FieldType>'. Did you mean to write 'references'?ts(2561)
auth-C42JqOR9.d.ts(1893, 17): The expected type comes from property 'userId' which is declared here on type '{ [x: string]: FieldAttribute<FieldType>; }'
(property) reference: {
model: string;
field: string;
onDelete: string;
}
Object literal may only specify known properties, but 'reference' does not exist in type 'FieldAttribute<FieldType>'. Did you mean to write 'references'?ts(2561)
auth-C42JqOR9.d.ts(1893, 17): The expected type comes from property 'userId' which is declared here on type '{ [x: string]: FieldAttribute<FieldType>; }'
(property) reference: {
model: string;
field: string;
onDelete: string;
}
My code:
fields: {
userId: {
type: 'string',
required: true,
unique: true,
reference: {
model: 'user',
field: 'id',
onDelete: 'cascade',
},
},
fields: {
userId: {
type: 'string',
required: true,
unique: true,
reference: {
model: 'user',
field: 'id',
onDelete: 'cascade',
},
},
13 replies
BABetter Auth
Created by Augustas Paliulis on 2/16/2025 in #help
Blocking specific routes based on user session
Hey, I was wondering what's the best approach to get user session and based on it prevent specific routes in website? I though of doing that through middleware, however inside middlare I can't get session using this method:
const session = await auth.api.getSession({
headers: await headers() // you need to pass the headers object.
})
const session = await auth.api.getSession({
headers: await headers() // you need to pass the headers object.
})
As I it is not allowed to use Node’s dgram module in Edge runtime What would be correct approach for this task?
10 replies
BABetter Auth
Created by Augustas Paliulis on 2/11/2025 in #help
Closing DB pool
Hello, I was reading Optimization guide, and noticed that a good practice for database optimization is closing it's connection pool:
Always close connections when they are no longer needed to return them to the pool
I am using MS SQL database with Kysely set up described in their documentation. Since I am pretty new with creating my own set up of database, I am a bit confused on this. So my Question is should I take care myself of closing this DB connection pool, or is it done by library? Is there a way to test it?
1 replies