mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-26 00:46:44 -05:00
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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user