Features

  • Password reset
  • Password policies
  • Password hashing and security

Overview

With an SMTP provider configured on your database, users with emails can reset their passwords with a two step process. First, the users requests a link to be sent to their email address. The auth service creates a token (saved to the auth.verification_tokens table in your database), and sends it in an email. The token is valid for 4 hours by default.

Installation

npm install @niledatabase/react

Usage

/user/reset-password

import { PasswordResetRequestForm } from "./path/to/ResetForm";

const MyComponent = () => {
  return <PasswordResetRequestForm callbackUrl="/change-password" />;
};

Once the user clicks on the link, they will be redirected to your app and will be able to securely reset their password.

/user/change-password

<PasswordResetForm
  defaultValues={{ email: "user@example.com" }}
  onSuccess={() => console.log("Password updated successfully")}
  onError={(error) => console.error("Update failed", error)}
/>

API

PasswordResetRequestForm Props

NameTypeDefaultDescription
clientQueryClient (optional)undefinedReact Query client instance.
callbackUrlstring (optional)undefinedThe URL to redirect to after a successful password reset.
defaultValuesobject (optional){ email: '', password: '', confirmPassword: '' }Default form values.
beforeMutate(data: AllowedAny) => AllowedAny (optional)undefinedFunction executed before mutation to modify request data.
onSuccess(res: Response) => void (optional)undefinedCallback triggered on successful password reset.
onError(error: Error, data: AllowedAny) => void (optional)undefinedCallback triggered if the reset process fails.

PasswordResetForm Props

NameTypeDefaultDescription
clientQueryClient (optional)undefinedReact Query client instance.
callbackUrlstring (optional)undefinedThe URL to redirect to after a successful password reset.
defaultValuesobject (optional){ email: '', password: '', confirmPassword: '' }Default form values.
beforeMutate(data: AllowedAny) => AllowedAny (optional)undefinedFunction executed before mutation to modify request data.
onSuccess(res: Response) => void (optional)undefinedCallback triggered on successful password reset.
onError(error: Error, data: AllowedAny) => void (optional)undefinedCallback triggered if the reset process fails.

Internal Functionality

  • Uses useForm from React Hook Form to handle form state.
  • Calls useResetPassword with the provided email and password upon form submission.
  • Implements password confirmation validation to ensure the user inputs matching passwords.
  • Supports lifecycle hooks (beforeMutate, onSuccess, onError) for request customization.
  • Disables the submit button if passwords do not match or required fields are missing.

Was this page helpful?