Skip to main content
The AuthConfig type provides hooks for authentication events. Configure these in your startApp call under the auth: key.

Validation Hooks

validateSignup

Called before a new user is created during email/password signup. Use this to enforce custom validation rules on signup data. Throw an error to reject the signup.
Props:
PropertyType
emailstring
passwordstring
firstNamestring | undefined
lastNamestring | undefined
avatarUrlstring | undefined
handlestring | undefined
Returns: void | Promise<void>

onBeforeSignup

Available since modelence@0.17.0.
Called after validateSignup and the built-in disposable-email check, but before the user document is inserted. Use this to plug in a custom domain-policy check (e.g. a tenant-specific email-domain verification service) without disabling the built-in disposable-email check. Throw an error to reject the signup — the thrown error is re-thrown to the caller and onSignupError fires. Currently only invoked for 'email' provider signups. OAuth signups are not gated because OAuth providers (Google, GitHub, etc.) do not issue disposable accounts.
To replace the built-in disposable-email check entirely with your own logic, set allowDisposableEmails: true (also available since modelence@0.17.0) and enforce your policy in onBeforeSignup.
Props:
PropertyType
emailstring
firstNamestring | undefined
lastNamestring | undefined
handlestring | undefined
provider'email'
connectionInfoConnectionInfo | undefined
Returns: void | Promise<void>

validateProfileUpdate

Called before a user’s profile is updated. Use this to enforce custom validation rules on profile updates. Throw an error to reject the update.
Props:
PropertyType
firstNamestring | undefined
lastNamestring | undefined
avatarUrlstring | undefined
handlestring | undefined
Returns: void | Promise<void>

Custom Handle Generation

generateHandle

By default, handles are derived from the user’s email address. This hook lets you generate custom handles based on the user’s email and profile information.
Props:
PropertyType
emailstring
firstNamestring | undefined
lastNamestring | undefined
Returns: string | Promise<string> — The generated handle. If the handle conflicts with an existing one, Modelence will automatically append a numeric suffix.

Auth Events

Error Rendering

errorComponent

Use errorComponent to customize how OAuth authentication errors are rendered. By default, OAuth errors are returned as JSON. Providing errorComponent allows you to return a custom HTML response instead. This is useful when OAuth flows are triggered in a browser context.

Full Example