docs(fix): Add reference to ctx object for database hooks (#1642)

* Add reference to ctx object in database hooks

This would have saved me time when I was look at implementing database hooks!

* typo

* chore: remove heading

---------

Co-authored-by: Bereket Engida <86073083+Bekacru@users.noreply.github.com>
This commit is contained in:
crutchtheclutch
2025-03-02 20:37:52 -08:00
committed by GitHub
parent da5ad11ec7
commit 46f10f36aa

View File

@@ -519,7 +519,7 @@ export const auth = betterAuth({
databaseHooks: {
user: {
create: {
before: async (user) => {
before: async (user, ctx) => {
// Modify the user object before it is created
return {
data: {
@@ -550,7 +550,7 @@ export const auth = betterAuth({
databaseHooks: {
user: {
create: {
before: async (user) => {
before: async (user, ctx) => {
if (user.isAgreedToTerms === false) {
// Your special condition.
// Send the API error.
@@ -568,6 +568,8 @@ export const auth = betterAuth({
});
```
Much like standard hooks, database hooks also provide a `ctx` object that offers a variety of useful properties. Learn more in the [Hooks Documentation](/docs/concepts/hooks#ctx).
## Plugins Schema
Plugins can define their own tables in the database to store additional data. They can also add columns to the core tables to store additional data. For example, the two factor authentication plugin adds the following columns to the `user` table: