Skip to content
id0n

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

FieldTypeRequiredDescription
namestringYesThe user's display name.
emailstringYesMust be a valid email address. Unique per environment.
passwordstringYesLength limits are set for your environment.
imagestringNoProfile image URL.
callbackURLstringNoWhere to send the user after email verification. Must be a registered URL.
rememberMebooleanNoKeep 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

FieldTypeRequiredDescription
emailstringYesThe user's email.
passwordstringYesThe user's password.
callbackURLstringNoWhere to send the user after sign-in.
rememberMebooleanNoDefaults to true.

Sign out

await authClient.signOut();

Errors to handle

CodeWhen
INVALID_EMAILThe email is not valid.
PASSWORD_TOO_SHORT, PASSWORD_TOO_LONGThe password is outside the environment's limits.
USER_ALREADY_EXISTS_USE_ANOTHER_EMAILAn account with that email exists.
INVALID_EMAIL_OR_PASSWORDWrong credentials.
EMAIL_NOT_VERIFIEDThe environment requires verification before sign-in.

See all error codes.

Method reference

The full client method reference is published with the Legation API reference.

On this page

Ask AI

Answers come from the published id0n docs, with links to their sources.