Authentication
Blanq uses the amazing Better Auth for authentication. This is a service that provides a lot of the boilerplate for authentication and user management. If these docs are missing info on auth, look at the Better Auth Docs.
The User Object
Currently the base user schema is simple and contains only the necessary fields for Better Auth to function.
export const users = sqliteTable('users', {
id: uuid,
name: text('name').notNull(),
email: text('email').unique().notNull(),
emailVerified: integer('email_verified', { mode: 'boolean' }).default(false).notNull(),
stripeCustomerId: text('stripe_customer_id').unique(),
image: text('image'),
createdAt: created_at,
updatedAt: updated_at,
deletedAt: deleted_at,
}, table => [
index('users_created_non_deleted_idx').on(table.createdAt).where(isNull(table.deletedAt)),
index('users_stripe_id_idx').on(table.stripeCustomerId),
])
Extending the User Object
If you need to add more fields to the user object, you can do so in the server/database/schemas/users.ts
file.
Once you've added your new field you can run:
pnpm db:generate
To generate the SQL migration file. Then finally, you need to update the server/utils/auth.ts
file to include the new field:
For example, this is how the stripeCustomerId
field is added (note how input
is false, so users can't update this field):
function createAuth() {
return betterAuth({
user: {
additionalFields: {
stripeCustomerId: {
type: 'string',
input: false,
},
},
...