Basic usage
Sign up, sign in, read the session and sign out.
These steps use email and password, the most common method. Other methods follow the same pattern.
Read the session
Framework clients expose useSession(), which keeps your UI in sync with the signed-in user. It loads the session in the browser. It does not fetch the session or write cookies during server-side rendering. See Sessions and cookies.
import { authClient } from "@/lib/auth-client";
const session = authClient.useSession();The shape of the returned value is documented in the client reference.
Sign up with email
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | The user's display name. |
email | string | Yes | Must be a valid email address. Unique per environment. |
password | string | Yes | Length limits are set for your environment. |
image | string | No | Profile image URL. |
callbackURL | string | No | Where to send the user after email verification. Must be a registered URL. |
rememberMe | boolean | No | Keep the session after the browser closes. |
Depending on your environment, a successful sign-up may sign the user in straight away, or require them to verify their email first.
Sign in with email
| Field | Type | Required | Description |
|---|---|---|---|
email | string | Yes | The user's email. |
password | string | Yes | The user's password. |
callbackURL | string | No | Where to send the user after sign-in. |
rememberMe | boolean | No | Defaults to true. |
Sign out
await authClient.signOut();Errors to handle
| Code | When |
|---|---|
INVALID_EMAIL | The email is not valid. |
PASSWORD_TOO_SHORT, PASSWORD_TOO_LONG | The password is outside the environment's limits. |
USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL | An account with that email exists. |
INVALID_EMAIL_OR_PASSWORD | Wrong credentials. |
EMAIL_NOT_VERIFIED | The environment requires verification before sign-in. |
See all error codes.
Method reference
The full client method reference is published with the Legation API reference.