Register
Create new user accounts and verify email addresses with the TypeScript SDK.
Register
Create new user accounts with email/password, collect profile data, and verify email addresses.
register()
Create a new user account with email, password, and optional profile traits.
register(params: RegisterParams): Promise<Session>Parameters
| Name | Type | Required | Description |
|---|---|---|---|
email | string | yes | User's email address |
password | string | yes | Password (min 8 characters, checked against breach database) |
traits | UserTraits | no | Profile data (name, phone, locale, timezone) |
organizationId | string | no | Register directly into an organization |
UserTraits
| Field | Type | Description |
|---|---|---|
name.first | string | First name |
name.last | string | Last name |
phone | string | Phone number in E.164 format |
locale | string | Preferred locale (e.g., "en-US") |
timezone | string | IANA timezone (e.g., "America/New_York") |
Returns
Promise<Session> -- The new session. The user is automatically logged in after registration. If email verification is required, the session is created but marked as unverified until the user confirms their email.
Basic usage
import { AvnologyId } from "@avnology/sdk-typescript";
const client = new AvnologyId({
baseUrl: "https://api.id.avnology.com",
clientId: "app_abc123",
});
const session = await client.register({
email: "[email protected]",
password: "SecurePassword123!",
traits: {
name: { first: "Jane", last: "Doe" },
phone: "+15550100",
locale: "en-US",
timezone: "America/New_York",
},
});
console.log(session.identity.id); // "usr_abc123..."
console.log(session.identity.email); // "[email protected]"
console.log(session.identity.verifiedAt); // null (pending verification)Organization registration
Register a user directly into an organization. The organization must allow open registration or the user must have an invitation.
const session = await client.register({
email: "[email protected]",
password: "SecurePassword123!",
traits: { name: { first: "Jane", last: "Doe" } },
organizationId: "org_abc123",
});
console.log(session.identity.organizationId); // "org_abc123"Registration with social provider
To register via a social provider (Google, GitHub, Microsoft, Apple), use the same loginWithProvider() method. If the user does not have an existing account, one is automatically created during the OAuth callback.
// This creates a new account if one doesn't exist
client.loginWithProvider("google", {
returnUrl: "/onboarding",
});Error handling
import {
DuplicateAccountError,
PasswordBreachedError,
PasswordTooWeakError,
ValidationError,
RegistrationDisabledError,
} from "@avnology/sdk-typescript";
try {
const session = await client.register({ email, password, traits });
} catch (error) {
if (error instanceof DuplicateAccountError) {
showError(
"An account with this email already exists. " +
"Try logging in or use a different email."
);
} else if (error instanceof PasswordBreachedError) {
showError(
"This password has been found in a data breach. " +
"Please choose a different password."
);
} else if (error instanceof PasswordTooWeakError) {
showError(`Password too weak: ${error.reason}`);
// error.reason: "too_short" | "no_uppercase" | "no_number" | "common_password"
// error.minLength: 8
} else if (error instanceof ValidationError) {
showFieldErrors(error.fieldErrors);
// e.g., [{ field: "traits.phone", message: "Invalid phone number format" }]
} else if (error instanceof RegistrationDisabledError) {
showError("Registration is currently disabled for this application.");
}
}verifyEmail()
Verify a user's email address using the verification code sent to their inbox.
verifyEmail(params: VerifyEmailParams): Promise<void>Parameters
| Name | Type | Required | Description |
|---|---|---|---|
code | string | yes | 6-digit verification code from email |
flowId | string | no | Flow ID (auto-detected from session if omitted) |
Basic usage
// After registration, the user receives a verification email with a code
await client.verifyEmail({ code: "482901" });
// Check the session to confirm verification
const session = await client.getSession();
console.log(session.identity.verifiedAt); // "2026-04-08T12:00:00Z"Resend verification email
await client.resendVerification({ email: "[email protected]" });
showMessage("Verification email sent. Check your inbox.");Error handling
import { InvalidCodeError, ExpiredFlowError } from "@avnology/sdk-typescript";
try {
await client.verifyEmail({ code });
} catch (error) {
if (error instanceof InvalidCodeError) {
showError("Invalid verification code. Check your email and try again.");
} else if (error instanceof ExpiredFlowError) {
showError("This verification code has expired. We'll send you a new one.");
await client.resendVerification({ email: userEmail });
}
}resendVerification()
Resend the email verification code.
resendVerification(params: ResendVerificationParams): Promise<void>Parameters
| Name | Type | Required | Description |
|---|---|---|---|
email | string | yes | Email address to resend verification to |
Returns
Promise<void> -- Resolves when the email is queued for delivery. Does not throw if the email is not found (to prevent email enumeration).
Common errors
| Error class | HTTP status | When |
|---|---|---|
DuplicateAccountError | 409 | Email already registered |
PasswordBreachedError | 400 | Password found in HIBP database |
PasswordTooWeakError | 400 | Password fails policy requirements |
ValidationError | 422 | Invalid field values |
RegistrationDisabledError | 403 | Registration disabled for this app/org |
InvalidCodeError | 400 | Wrong verification code |
ExpiredFlowError | 410 | Verification code expired |
RateLimitError | 429 | Too many requests |
See also
- Login -- Authenticate existing users
- Session -- Session management
- User type -- User and Identity types
- Error types -- Full error hierarchy