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.
Returns:
void | Promise<void>
validatePassword
Enforces your password policy on every path that sets a password — signup and password
reset today, plus any future change-password flow. Throw an error to reject the password;
the message is surfaced to the client.
This is the hook to use for password rules. Modelence enforces a built-in floor of 8
characters (and a 128-character ceiling) before calling it, so your hook only needs to add
your own rules on top.
Returns:
void | Promise<void>
Use context when a flow needs different treatment — for example, checking a
breach-database only on reset:
onBeforeSignup
Available since
modelence@0.17.0.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.
Invoked for 'email' and 'magicLink' provider signups. OAuth signups are not gated because OAuth providers (Google, GitHub, etc.) do not issue disposable accounts.
allowDisposableEmails: true (also available since modelence@0.17.0) and enforce your policy in onBeforeSignup.
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.
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.
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 Handling
OAuth errors surface at the provider callback URL (/api/_internal/auth/...), which is a server route outside your client bundle. Nothing there can render your app’s UI, so by default the user lands on a JSON body with no way back. Two options change that.
oauthErrorRedirectUrl
Use oauthErrorRedirectUrl to send the browser back into your app when a web OAuth flow fails. It accepts a path, resolved against your site URL (MODELENCE_SITE_URL), or an absolute URL. The failure is appended as ?error=<message>&errorCode=<code>, the same contract a mobile flow delivers on its deep link, so your app can show it on a real page.
error is for display and its wording may change. Branch on errorCode (invalid_state, email_exists, account_inactive, …) for anything programmatic.
When both oauthErrorRedirectUrl and errorComponent are set, the redirect wins and errorComponent is not called.
errorComponent (deprecated)
errorComponent is deprecated in favor of oauthErrorRedirectUrl. It renders OAuth errors as a standalone HTML document at the callback URL instead of JSON, which means the page cannot use your app’s UI. It is still honored for existing apps, but is ignored whenever oauthErrorRedirectUrl is set.