From 46f10f36aaed0903f0bbf50a4f2b497722e4fc4a Mon Sep 17 00:00:00 2001 From: crutchtheclutch Date: Sun, 2 Mar 2025 20:37:52 -0800 Subject: [PATCH] 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> --- docs/content/docs/concepts/database.mdx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/content/docs/concepts/database.mdx b/docs/content/docs/concepts/database.mdx index 470afe21db..a8dcc00dd2 100644 --- a/docs/content/docs/concepts/database.mdx +++ b/docs/content/docs/concepts/database.mdx @@ -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: