Unidy Docs

Sign-in and registration operations

Implement password and email-code authentication, registration, and recovery with the SDK HTTP API.

Use these endpoints when your application calls the SDK HTTP API directly. Existing-account sign-in uses a sid; unfinished registration uses a separate rid. Neither identifier is a signed-in user token.

For the choice between hosted and embedded journeys, start with Registration and account recovery. For storing, refreshing, and ending an authenticated session, use API keys, JWTs and refresh tokens.

Prepare requests

Send requests to your brand's Unidy host. Every JSON operation below requires an SDK application's API key; the host must belong to a brand allowed for that SDK application.

http
Authorization: Bearer YOUR_SDK_API_KEY
Accept: application/json
Content-Type: application/json
SDK-Version: 1.12.0

SDK-Version is a request header. Use a supported semantic version whose authentication contract your integration implements. The current brand-connection continuation is enabled for versions greater than 1.2.0; omitting the header takes the legacy path. Putting sdkVersion in the JSON body does not enable that continuation. Browser requests supply User-Agent automatically; other clients must supply one when creating a sign-in or registration.

On operations with CAPTCHA enabled, include the widget's current captcha_token in the JSON body. Handle captcha_token_missing, captcha_verification_failed, and captcha_score_too_low as 403 responses requiring a new challenge or a user-visible failure.

Sign in an existing account

Start and choose a method

http
POST /api/sdk/v1/sign_ins

{"email":"alex@example.com","originUrl":"https://app.example.com/login"}

A 201 response includes sid, status, expires_at, email, login_options, and connected_to_brand. Keep the returned sid as your sign_in_id for the following requests. Render the available methods from login_options; a newly created sign-in normally has status pending_verification and expires one hour after creation.

There are two useful shortcuts:

Request body additionResult
"password":"USER_ENTERED_PASSWORD"Attempts password authentication immediately. Success includes jwt and refresh_token alongside the sign-in record.
"sendMagicCode":trueCreates the sign-in and attempts to send an email code. The response includes a resend delay or error_identifier; it does not contain authenticated-session tokens.

Choose one shortcut. In particular, inspect the body even after 201 when using sendMagicCode: a send failure can be returned as error_identifier inside the created sign-in response.

An email-only or password start returns 422 account_unconfirmed for an unconfirmed account. The body can include login_type: "invited" or "unconfirmed"; use the appropriate recovery path below. Starting with sendMagicCode: true supports the email-code path for an unconfirmed account, subject to the brand's login policy.

Authenticate with a password or email code

OperationMethod and pathJSON bodySuccessful result
PasswordPOST /api/sdk/v1/sign_ins/{sid}/authenticate{"password":"USER_ENTERED_PASSWORD"}201 with jwt and refresh_token, or a continuation below.
Send or resend email codePOST /api/sdk/v1/sign_ins/{sid}/send_magic_code{}201 with enable_resend_after.
Verify email codePOST /api/sdk/v1/sign_ins/{sid}/authenticate{"code":"1234"}201 with jwt and refresh_token, or a continuation below.

Send either password or code to authenticate, not both. A code is single-use. A valid email code can confirm an unconfirmed account, except where the brand's manual-login policy prevents automatic confirmation.

Complete the returned continuation

Correct credentials do not always finish the journey. Drive the next screen from the response:

ResponseNext action
201 containing jwt and refresh_tokenEstablish the SDK user session using those tokens.
424 brand_connection_requiredKeep meta.sid; ask the user to connect to this brand, then submit the brand-connect request.
424 missing_required_fieldsKeep meta.sid; render the returned meta.fields and submit the missing values.
Authentication errorKeep the user on the relevant method or recovery screen; do not infer authentication from having a sid.

The brand-connect request is made after successful credential verification:

http
POST /api/sdk/v1/sign_ins/{sid}/brand_connect

{}

It returns 201 with jwt and refresh_token, or 424 missing_required_fields. A connected_to_brand: false value on the initial record is useful for explaining the journey, but it is not permission to connect an unauthenticated sign-in.

To supply missing profile values, nest them under user. Standard fields are direct children; custom attributes go under user.custom_attributes:

http
PATCH /api/sdk/v1/sign_ins/{sid}/update_required_fields

{
  "user": {
    "first_name": "Alex",
    "last_name": "Rivera",
    "custom_attributes": {"membership_type":"supporter"}
  }
}

Use the brand's returned field definitions; these names are examples. Success returns 201 with jwt and refresh_token. An incomplete or invalid update returns 424 with missing_required_fields or update_failed; these update responses can put fields at the top level instead of meta.fields. Preserve user input and show the remaining errors. Locked fields cannot be changed through this operation.

Do not call authenticate repeatedly after credential verification has succeeded: an authenticated sign-in returns 422 sign_in_already_processed. Continue with brand connection or required fields when instructed. If the sign-in expires, start again and authenticate again.

Confirm or recover an existing account

Send a fresh confirmation message for an unconfirmed account:

http
POST /api/sdk/v1/sign_ins/resend_confirmation

{"email":"alex@example.com","return_to":"https://app.example.com/login"}

The optional return_to must match an allowed SDK redirect URI. Success is 200 with enable_resend_after in seconds. A recent send returns 429 confirmation_recently_sent; an already-confirmed account returns 422 account_already_confirmed, so offer sign-in. Confirmation happens through the emailed link, then the user can start or resume the appropriate sign-in journey.

For login_type: "invited", use POST /api/sdk/v1/sign_ins/resend_invitation with the same email and optional return_to fields. Invitation acceptance and password reset have their own tokens and endpoints; follow Registration and account recovery instead of creating a second account.

Register a new account

Registration stores an unfinished flow before creating a user. Choose screens to suit your journey; email, authentication method, profile data, and newsletter preferences do not have one mandatory screen order. Use can_finalize and the returned state to decide whether completion is possible.

Create and update the flow

http
POST /api/sdk/v1/registration

{
  "registration_url": "https://app.example.com/register",
  "email": "alex@example.com",
  "passwordless_flag": true
}

Only registration_url is required to create the flow. Use a URL in your application that can resume registration. The brand defaults to the request's host. An existing account produces 422 email_already_registered; an existing active registration can produce 409 registration_flow_already_exists. Offer sign-in or resume rather than automatically restarting.

A 201 response includes:

FieldUse
ridIdentifier for subsequent registration operations. It is not a sign-in sid.
statusObject of completion flags, such as email_collected or email_verified; not a single sequential step.
can_finalizeWhether the collected data currently meets the completion prerequisites.
email_verified, has_password, has_passkey, social_providerAuthentication and verification state. has_password can be null before a method is chosen.
registration_profile_data, newsletter_preferencesSaved values for restoring the form.
expires_at, expiredWhether this flow can still be continued. The flow lasts 15 days from creation.

Read it again with GET /api/sdk/v1/registration?rid={rid}. Add collected values with:

http
PATCH /api/sdk/v1/registration?rid={rid}

{
  "registration_profile_data": {
    "first_name": "Alex",
    "last_name": "Rivera"
  }
}

Updates return 200 with the refreshed flow. You may also submit email, password, passwordless_flag, and newsletter_preferences here or during creation. A password must satisfy the brand policy. Once set, the flow's email cannot be changed: email_cannot_be_changed requires an explicit cancellation and a new flow if the address was wrong.

Newsletter keys are newsletter internal names; array values are preference identifiers configured for that newsletter. Collect the user's choices explicitly. An empty preference array can select configured defaults or all preferences, so it must not be used to mean “declined.” Omit newsletters the user did not select.

Verify the email when your journey needs it

OperationMethod and pathBodyResult
Send verification codePOST /api/sdk/v1/registration/email_verification/send_code?rid={rid}{}200 with success and enable_resend_after. Requires an email already saved on the flow.
Verify codePOST /api/sdk/v1/registration/email_verification/verify?rid={rid}{"code":"1234"}200 with the flow and email_verified: true.

Registration verification codes and sign-in codes serve different purposes; submit each to its own endpoint. Resend delays returned for these email-code operations, like sign-in magic-code delays, are milliseconds. Confirmation-resend delays above are seconds; do not share a countdown implementation without normalizing the units.

Finalize and inspect the result

When can_finalize is true:

http
POST /api/sdk/v1/registration/finalize?rid={rid}

{}

The server checks required profile fields and an authentication method again. Most journeys require an email; configured KYC provider journeys can supply identity without a real email initially. Email verification is not universally required before finalization.

Successful finalization returns 200 with the flow. What happens next depends on confirmation:

ResponseYour next screen
Includes auth: {"id_token":"…","refresh_token":"…"}The account is confirmed and an SDK session was created. Store the tokens through your session layer.
Has no authThe account was created but no SDK session was returned. Show the confirmation-email next step and then offer sign-in.
422 cannot_finalizeUse meta.missing_fields, meta.email_missing, or meta.auth_method_missing when present to collect missing data.

Registration uses auth.id_token, while sign-in uses jwt at the top level. Normalize these response shapes deliberately. A successful registration response alone is not proof that the user has an authenticated session.

Resume or cancel

Keep the rid only as long as your application needs to resume the unfinished flow. If the browser no longer has it, request a resume email:

http
POST /api/sdk/v1/registration/resume

{"email":"alex@example.com"}

Success returns 200 {"success":true}. The emailed link is a browser-navigation endpoint that does not require an API-key header. It redirects to the saved registration URL with registration_rid; retrieve that flow before choosing the next screen. Using the email link also verifies the flow's email.

DELETE /api/sdk/v1/registration?rid={rid} cancels an unfinished flow and returns 200 {"success":true}. Completed flows cannot be continued or canceled through this endpoint. After a finalization request with an uncertain network result, check the existing flow and offer sign-in when it was already processed; do not automatically create another registration.

Social-provider, passkey, and internal-matching branches add their own redirect, WebAuthn, or matching steps. Use their dedicated guidance from Registration and account recovery; do not insert them as mandatory steps into every registration.

Handle failures without losing progress

Inspect error_identifier and the HTTP status. Additional detail usually lives in meta or error_details; some sign-in operations return fields directly on the response body.

Status and identifierAction
401 missing_api_key / invalid_api_key; 403 origin_not_allowedCorrect the SDK key and brand host configuration.
404 account_not_foundOffer registration or let the user correct the email.
401 invalid_passwordKeep the email/sign-in context and allow another attempt or account recovery.
401 magic_code_not_valid / magic_code_expired / magic_code_usedCorrect the code or send a new one once resending is allowed.
401 account_lockedStop automatic attempts. This can be an administrator lock or a temporary failed-attempt lock; do not promise one fixed unlock time.
422 magic_code_recently_createdRespect the returned meta.enable_resend_after in milliseconds; a shortcut create response can return this delay at the top level.
404 sign_in_not_found; 422 sign_in_expiredStart a new sign-in and verify credentials again.
422 sign_in_not_authenticatedReturn to credential verification; possession of a sid cannot authorize profile completion or brand connection.
422 password_validation_failed / profile_validation_failedDisplay the returned password or field errors and preserve unaffected registration values.
404 registration_not_found; 422 registration_expiredOffer a new registration after explaining that the prior flow is unavailable.
422 registration_already_processed / email_already_registeredOffer sign-in or account recovery.
422 invalid_verification_code / verification_code_expired / verification_code_already_usedRetry the registration code or request a fresh one.
429 verification_code_recently_sentWait for meta.enable_resend_after in milliseconds before sending another registration code.
429 rate_limit_exceededPause requests. Use an available Retry-After header, otherwise bounded backoff; do not assume every throttled response contains a countdown.

Persist an authenticated session only when the relevant response actually contains its tokens. Continue with API keys, JWTs and refresh tokens for refresh, authenticated requests, and sign-out.

Was this page helpful?