Email sign-in
This page is the reference for IdentityHound’s email sign-in component: what it needs from your app, its props, parts, events, and agent actions, and the tested example. The component signs a principal in with a 6-digit code sent to their email and runs the whole flow: the address, the code (typed, pasted, or filled in from the email), resending after the wait, changing the address, the guesses left, and an error message for each failure.
It is built on UI SDK, so you restyle or rearrange its parts, and an agent your app allows takes the same steps a human does. To add it to an app step by step, follow Add email sign-in.
Frameworks
- React 19:
EmailCodeSignInand its parts, from@agentpost-tools/identityhound-ui/react. - Web Components: the
<ih-email-code-sign-in>elements, from@agentpost-tools/identityhound-ui/web, for any page or framework. - React Native: unstyled parts, from
@agentpost-tools/identityhound-ui/native, and a finished screen you copy into your app; React Native shows how to add them.
Use React when your app renders with React 19, and Web Components otherwise. Both render the same UI SDK primitive over the same workflow, so they behave the same. The React Native parts run the same workflow and show the same words, without UI SDK.
Install and set up
An app uses these packages.
| Package | What it holds |
|---|---|
@agentpost-tools/identityhound-ui |
The component: the primitive (.), React (./react), Web Components (./web), React Native (./native), and the default look (./styles.css) |
@agentpost-tools/identityhound-sdk |
The workflow it runs, and where the session is kept (./workflows); for a server, ./server |
@agentpost-tools/identityhound-react |
IdentityhoundProvider and useSession, for React |
@ui-sdk/core, @ui-sdk/react or @ui-sdk/web |
UI SDK, at exactly 0.1.0-beta.2 |
For React:
npm i @agentpost-tools/identityhound-ui @agentpost-tools/identityhound-react @ui-sdk/react@0.1.0-beta.2 react react-dom
For Web Components:
npm i @agentpost-tools/identityhound-ui @ui-sdk/web@0.1.0-beta.2
The component needs three things from your app:
- IdentityHound’s sign-in settings. Email sign-in is on by default (
signIn.emailCode.enabled). A code lasts 10 minutes, and a new one can be sent after 30 seconds (codeTtlandresendAfter); the component counts down from what the API answers. WithsignUp.modeatopen, the default, a first sign-in creates the principal. Your server changes them through the config. - Your publishable key,
publishableKey, listing your app’s origins inallowedOrigins. It is safe in the page’s code. Publishable keys has the origin rule, and Create a project and issue a key creates one. - A session strategy, passed as
sessiontocreateIdentity, or toIdentityhoundProviderin React. The component works the same with either:serverSession()when your app has a server on the same origin as its pages. The server checks the code and keeps the session in an HTTP-only cookie, so the page’s JavaScript never sees it. Keep the session on your server builds it.deviceSession({ storage: localStorage })only when your app has no server. The browser keeps the session, where any script on the page can read it.
The component gets its identity from IdentityhoundProvider in React, or from an identity prop. As Web Components, set the root element’s identity property to what createIdentity returns.
Props
Each prop is a React prop on EmailCodeSignIn and its root part, and a property or attribute of the <ih-email-code-sign-in> element. Every prop is optional.
identity,Identity: The identity to sign in to, fromcreateIdentity. Without it, the one fromIdentityhoundProvider. A web component takes it as a property.email,string: The address to start with, such as from a sign-in link. Web Components: theemailattribute.errorMessage,(error: EmailCodeSignInFailure, context: EmailCodeErrorContext) => string | undefined: The words for an error, to change or translate the defaults. Return nothing to keep the default. Web Components: theerrorMessageproperty.signedIn,ReactNode: What shows once the principal is signed in. Defaults to a short confirmation. Only onEmailCodeSignIn, the React card.
Parts
The default presentation is EmailCodeSignIn in React, and emailCodeSignInMarkup() inside <ih-email-code-sign-in> for Web Components. For your own layout, compose the parts: each is a React component from @agentpost-tools/identityhound-ui/react and a custom element from @agentpost-tools/identityhound-ui/web. Put your own markup, words, and classes around and inside them; a part keeps its behavior wherever it sits in the root.
root:EmailCodeSignInRootin React,<ih-email-code-sign-in>as a web component. Holds the sign-in, and names it by its title as a region, so a screen reader can jump to it and an agent finds it by name.title:EmailCodeSignInTitlein React,<ih-email-code-sign-in-title>as a web component. The heading that names the sign-in. It stays the same through every step.description:EmailCodeSignInDescriptionin React,<ih-email-code-sign-in-description>as a web component. The line under the title, such as where the code went. Its words change with the step.email-step:EmailCodeSignInEmailStepin React,<ih-email-code-sign-in-email-step>as a web component. The form that asks for the email address. Shown on theemailstep. Submitting it requests a code.code-step:EmailCodeSignInCodeStepin React,<ih-email-code-sign-in-code-step>as a web component. The form that asks for the code. Shown on thecodestep. Submitting it, or typing, pasting, or autofilling a complete code, checks the code.signed-in:EmailCodeSignInSignedInin React,<ih-email-code-sign-in-signed-in>as a web component. What shows on thesigned_instep.field:EmailCodeSignInFieldin React,<ih-email-code-sign-in-field>as a web component. Wraps a step’s field, and marks it invalid when the error is about what was typed. Propname: the field it wraps,emailorcode.alert:EmailCodeSignInAlertin React,<ih-email-code-sign-in-alert>as a web component. Shows an error about the whole form, such as a network failure or too many tries. Shown only while there is one.send:EmailCodeSignInSendin React,<ih-email-code-sign-in-send>as a web component. The email step’s submit button.verify:EmailCodeSignInVerifyin React,<ih-email-code-sign-in-verify>as a web component. The code step’s submit button.resend:EmailCodeSignInResendin React,<ih-email-code-sign-in-resend>as a web component. Sends a new code. It stays a button in the Tab order during the wait, with the countdown in its name.change-email:EmailCodeSignInChangeEmailin React,<ih-email-code-sign-in-change-email>as a web component. Goes back to the email step, keeping the address, to use another one.when:EmailCodeSignInWhenin React,<ih-email-code-sign-in-when>as a web component. Shows its content only on one step, or only while the resend wait runs or after it ends. For markup that can’t branch on state, such as Web Components. Propstep: the step to show on:email,code, orsigned_in. Propresend:waitingto show during the wait, orreadyafter it.value:EmailCodeSignInValuein React,<ih-email-code-sign-in-value>as a web component. Shows one value as text. For markup that can’t render state, such as Web Components. Propname: the value to show:email,resendIn, ormessage.
Styling
Each part’s element has data-slot="email-code-sign-in-<part>", and the root data-slot="email-code-sign-in". These attributes follow the component’s state:
| Part | Attribute | Meaning |
|---|---|---|
root |
data-step |
The step shown: email, code, or signed_in. |
root |
data-pending |
Set while a request is out. |
root |
aria-busy |
true while a request is out. |
email-step |
data-pending |
Set while a request is out. |
code-step |
data-pending |
Set while a request is out. |
field |
data-invalid |
Set when the error is about this field. |
send |
aria-disabled |
true while a request is out. |
send |
data-pending |
Set while the code request is out. |
verify |
aria-disabled |
true while a request is out. |
verify |
data-pending |
Set while the code is being checked. |
resend |
aria-disabled |
true while a request is out or the wait runs. |
resend |
data-waiting |
Set while the wait runs. |
resend |
data-pending |
Set while the new code is being sent. |
change-email |
aria-disabled |
true while the code is being checked. |
For the default look, import UI SDK’s stylesheet and the component’s, as the example does:
import '@ui-sdk/core/web.css';
import '@agentpost-tools/identityhound-ui/styles.css';
For your own look, style the parts’ attributes with your own CSS. UI SDK’s styling guide explains how parts take styles, and the docs in your installed @ui-sdk/react or @ui-sdk/web package (docs/llms.txt) match its version.
@agentpost-tools/identityhound-ui/styles.css sets these custom properties on the root, for your CSS to change: --ih-gap, --ih-radius, --ih-border, --ih-surface, --ih-text, --ih-muted, --ih-accent, --ih-on-accent, --ih-danger, --ih-focus.
Events
In React, pass a callback prop. On <ih-email-code-sign-in>, listen for the event; its detail holds the callback’s argument, and it doesn’t bubble.
| React | Web Components event | Argument | When it runs |
|---|---|---|---|
onSignedIn |
signedin |
SignedIn |
Runs once the principal is signed in, with who it is. A web component fires signedin. |
onStepChange |
stepchange |
EmailCodeStep |
Runs when the step changes: email, code, or signed_in. A web component fires stepchange. |
Agent actions
An agent signs a principal in through this component with the four actions below, and reads each one’s outcome from the step’s result and the snapshot.
Your app connects the agent through UI SDK’s agent bridge and chooses which actions it may take. UI SDK’s Connect an agent and its skill cover creating the bridge, its allow function, and giving it to an agent. The example connects it and allows every action:
import { createAgent, registerTools } from '@ui-sdk/react/agent';
// The app decides which steps an agent may run; signing in needs nobody to confirm.
const agent = createAgent({ allow: () => true });
registerTools(agent, { allow: () => true });
Calling an action starts it; it is not success. The bridge waits while the action’s request is out, then reports that action’s own outcome:
- Success: the step returns
ok: trueonly when the action itself succeeded, and itschangesshow the newstep. - Failure: the step returns
ok: false, anderror.messageends with the action’s own error code, even when another request, such as one typed by hand, is out. The snapshot’serrorandmessageshow the code too, except where the table says Not in the snapshot.
Read the snapshot after each step: pending is true while a request is out, and pendingAction names it.
requestCode(email)
Sends a code to the address and moves to the code step.
email: The address to send the code to.- While pending:
pendingistrue, andpendingActionis"request". - Success:
stepbecomes"code". - Dropped: when the address changes before the answer comes, the answer is dropped: the step fails with
superseded, and the snapshot stays on the email step.
| Failure | Comes from | What the page shows, or the snapshot shows |
|---|---|---|
email_required |
Before any request | Enter your email address. |
signed_in |
Before any request | You’re already signed in. |
busy |
Before any request | Not in the snapshot. Another request is still out, such as one a principal started. The snapshot keeps showing that request. |
not_configured |
Before any request | Not in the snapshot. The component has no identity yet. The snapshot stays on the email step. |
invalid_request |
The request | Enter a valid email address, like name@example.com. |
sign_in_disabled |
The request | Email sign-in is turned off for this app. |
origin_not_allowed |
The request | This site isn’t set up for sign-in yet. |
throttled |
The request | Too many tries. Wait a moment and try again. |
network_error |
The request | We couldn’t reach the sign-in service. Check your connection and try again. |
verifyCode(code)
Signs in with the emailed code.
code: The 6-digit code from the email. An agent never reads it back.- While pending:
pendingistrue, andpendingActionis"verify". - Success:
stepbecomes"signed_in".
| Failure | Comes from | What the page shows, or the snapshot shows |
|---|---|---|
no_code_sent |
Before any request | Send a code to your email first. |
signed_in |
Before any request | You’re already signed in. |
code_required |
Before any request | Enter the 6-digit code from the email. |
busy |
Before any request | Not in the snapshot. Another request is still out, such as one a principal started. The snapshot keeps showing that request. |
not_configured |
Before any request | Not in the snapshot. The component has no identity yet. The snapshot stays on the email step. |
invalid_request |
The request | Enter the 6-digit code from the email. |
code_invalid |
The request | That code is wrong. 4 tries left. |
code_expired |
The request | That code expired. Send a new one. |
sign_up_closed |
The request | That email has no account here. Check the address, or ask for an invitation. |
origin_not_allowed |
The request | This site isn’t set up for sign-in yet. |
throttled |
The request | Too many tries. Wait a moment and try again. |
session_not_saved |
The request | We couldn’t keep you signed in on this device. Try again. |
network_error |
The request | We couldn’t reach the sign-in service. Check your connection and try again. |
resend()
Sends a new code to the same address, once the wait is over.
- While pending:
pendingistrue, andpendingActionis"resend". - Success:
stepbecomes"code". - Dropped: when the address changes before the answer comes, the answer is dropped: the step fails with
superseded, and the snapshot stays on the email step.
| Failure | Comes from | What the page shows, or the snapshot shows |
|---|---|---|
no_code_sent |
Before any request | Send a code to your email first. |
resend_too_soon |
Before any request | Wait a moment before sending a new code. |
busy |
Before any request | Not in the snapshot. Another request is still out, such as one a principal started. The snapshot keeps showing that request. |
not_configured |
Before any request | Not in the snapshot. The component has no identity yet. The snapshot stays on the email step. |
sign_in_disabled |
The request | Email sign-in is turned off for this app. |
origin_not_allowed |
The request | This site isn’t set up for sign-in yet. |
throttled |
The request | Too many tries. Wait a moment and try again. |
network_error |
The request | We couldn’t reach the sign-in service. Check your connection and try again. |
changeEmail()
Goes back to the email step, to use another address. It answers at once, with no request.
- While pending: never; it answers at once.
- Success:
stepbecomes"email".
| Failure | Comes from | What the page shows, or the snapshot shows |
|---|---|---|
busy |
Before any request | Not in the snapshot. Another request is still out, such as one a principal started. The snapshot keeps showing that request. |
not_configured |
Before any request | Not in the snapshot. The component has no identity yet. The snapshot stays on the email step. |
What an agent reads
The sign-in in an agent’s snapshot after a wrong code. The state keys are the component’s own; actions lists what an agent may call.
{
"component": "email-code-sign-in",
"label": "Sign in",
"step": "code",
"email": "ana@example.com",
"pending": false,
"pendingAction": null,
"error": "code_invalid",
"message": "That code is wrong. 4 tries left.",
"guessesLeft": 4,
"resendIn": 30,
"actions": ["requestCode", "verifyCode", "resend", "changeEmail"]
}
The code field once a code is typed into it. Its value is always redacted:
{
"component": "otp-input",
"label": "Code",
"value": "[redacted]"
}
What agent.act returns for the wrong code:
{
"ok": false,
"error": {
"step": 0,
"message": "verifyCode on Sign in (c3) failed: code_invalid"
}
}
These values never reach an agent: not in the snapshot, a step’s result, or a change event.
| Value | How it stays out |
|---|---|
| The emailed code | The code field reads "[redacted]" once it is filled. The argument to verifyCode never appears in the state, the step’s result, or a change event. |
| Session tokens | The component never holds one. The session strategy keeps the session, on the device or on your server. |
| User tokens | The component never holds one. The identity keeps them in memory, outside the component. |
| The verification ID | The workflow keeps it, and the state never shows it. |
Example
This is our example app’s code, which its tests run against IdentityHound: a human signs in with the keyboard, an agent signs in through the bridge, and the code and tokens stay out of what the agent reads. The React card keeps the session in the browser; the Web Components arrange the parts in a layout of their own, with the address and its button on one row. baseUrl and fetch are for the tests; leave them out to use the hosted API.
// Sign principals in with IdentityHound's email-code component, in React.
//
// The provider holds the identity: the project's publishable key, and where
// the session is kept. Here the browser keeps it, with `deviceSession`; an
// app with its own server passes a session strategy whose server keeps it in
// an HTTP-only cookie instead. The component runs the whole sign-in: the
// email, the code, resend, change-email, and the errors.
import {
IdentityhoundProvider,
useSession,
} from '@agentpost-tools/identityhound-react';
import {
deviceSession,
type IdentityOptions,
} from '@agentpost-tools/identityhound-sdk/workflows';
import { EmailCodeSignIn } from '@agentpost-tools/identityhound-ui/react';
export interface SignInAppProps {
/** The project's publishable key, `pk_test_…` or `pk_live_…`. */
publishableKey: string;
/** IdentityHound's API root. Defaults to Agentpost's hosted API. */
baseUrl?: string;
fetch?: IdentityOptions['fetch'];
}
export function SignInApp({ publishableKey, baseUrl, fetch }: SignInAppProps) {
return (
<IdentityhoundProvider
publishableKey={publishableKey}
session={deviceSession({ storage: localStorage })}
baseUrl={baseUrl}
fetch={fetch}
>
<Account />
</IdentityhoundProvider>
);
}
function Account() {
const session = useSession();
if (session.status === 'loading') return <p>Loading…</p>;
if (session.status === 'signed_in')
return (
<p>
{session.principal.displayName
? `Signed in as ${session.principal.displayName}. `
: 'Signed in. '}
<button type="button" onClick={() => void session.signOut()}>
Sign out
</button>
</p>
);
return <EmailCodeSignIn />;
}
// Sign principals in with IdentityHound's email-code component, as Web
// Components, in a compact layout of the parts: one row for the address,
// one for the code. The same primitive and workflow as the React card.
import {
createIdentity,
deviceSession,
type Identity,
type IdentityOptions,
type SignedIn,
} from '@agentpost-tools/identityhound-sdk/workflows';
import '@agentpost-tools/identityhound-ui/web';
export interface SignInElementOptions {
/** The project's publishable key, `pk_test_…` or `pk_live_…`. */
publishableKey: string;
/** IdentityHound's API root. Defaults to Agentpost's hosted API. */
baseUrl?: string;
fetch?: IdentityOptions['fetch'];
/** Runs once the principal is signed in. */
onSignedIn?: (signedIn: SignedIn) => void;
}
const SLOTS = '<ui-otp-input-slot></ui-otp-input-slot>'.repeat(6);
export function mountSignIn(
container: HTMLElement,
{ onSignedIn, ...options }: SignInElementOptions,
): Identity {
const identity = createIdentity({
...options,
session: deviceSession({
storage: localStorage,
key: 'identityhound.web-session',
}),
});
container.innerHTML = `
<ih-email-code-sign-in data-layout="inline">
<ih-email-code-sign-in-title><h2>Use an email code</h2></ih-email-code-sign-in-title>
<ih-email-code-sign-in-email-step><form>
<ih-email-code-sign-in-field name="email"><ui-field>
<ui-field-label>Work email</ui-field-label>
<div data-inline>
<ui-input><input name="email" type="email" autocomplete="email" inputmode="email" autocapitalize="none" spellcheck="false" /></ui-input>
<ih-email-code-sign-in-send><button>Send code</button></ih-email-code-sign-in-send>
</div>
<ui-field-error match="true"><ih-email-code-sign-in-value name="message"></ih-email-code-sign-in-value></ui-field-error>
</ui-field></ih-email-code-sign-in-field>
<ih-email-code-sign-in-alert><ih-email-code-sign-in-value name="message"></ih-email-code-sign-in-value></ih-email-code-sign-in-alert>
</form></ih-email-code-sign-in-email-step>
<ih-email-code-sign-in-code-step><form>
<ih-email-code-sign-in-field name="code"><ui-field>
<ui-field-label>Code sent to <ih-email-code-sign-in-value name="email"></ih-email-code-sign-in-value></ui-field-label>
<div data-inline>
<ui-otp-input name="code" max-length="6"><ui-otp-input-group>${SLOTS}</ui-otp-input-group></ui-otp-input>
<ih-email-code-sign-in-verify><button>Verify</button></ih-email-code-sign-in-verify>
</div>
<ui-field-error match="true"><ih-email-code-sign-in-value name="message"></ih-email-code-sign-in-value></ui-field-error>
</ui-field></ih-email-code-sign-in-field>
<ih-email-code-sign-in-alert><ih-email-code-sign-in-value name="message"></ih-email-code-sign-in-value></ih-email-code-sign-in-alert>
<p data-links>
<ih-email-code-sign-in-resend><button><ih-email-code-sign-in-when resend="ready">Send again</ih-email-code-sign-in-when><ih-email-code-sign-in-when resend="waiting">Send again in <ih-email-code-sign-in-value name="resendIn"></ih-email-code-sign-in-value>s</ih-email-code-sign-in-when></button></ih-email-code-sign-in-resend>
<ih-email-code-sign-in-change-email><button>Change email</button></ih-email-code-sign-in-change-email>
</p>
</form></ih-email-code-sign-in-code-step>
<ih-email-code-sign-in-signed-in><p>Signed in.</p></ih-email-code-sign-in-signed-in>
</ih-email-code-sign-in>`;
const element = container.querySelector('ih-email-code-sign-in') as
(HTMLElement & { identity?: Identity }) | null;
element!.identity = identity;
if (onSignedIn)
element!.addEventListener('signedin', (event) =>
onSignedIn((event as CustomEvent<SignedIn>).detail),
);
return identity;
}
React Native
In a React Native or Expo app, the sign-in comes in two layers: unstyled parts that run the sign-in, and a finished screen made of them that you copy into your app and change as you like. The parts run the same workflow as the web component and show the same words for each error. Package updates bring fixes to the parts, and the look stays yours.
Install the packages:
npx expo install @agentpost-tools/identityhound-ui @agentpost-tools/identityhound-react @agentpost-tools/identityhound-sdk
Then copy the finished screen into your app. In an app with a components.json, such as one using React Native Reusables:
npx shadcn@latest add https://agentpost.tools/r/identityhound/native/email-code-sign-in.json
In any other app, download the file:
curl -o components/email-code-sign-in.tsx https://agentpost.tools/r/identityhound/native/email-code-sign-in.tsx
Render EmailCodeSignIn from that file inside IdentityhoundProvider, with the session in the keychain, as Native apps sets up. It takes the same props as the web component, and signedIn for what shows afterward. The screen uses plain StyleSheet styles with its colors at the top of the file; restyle it, reword it, or rearrange its parts. To check who may use your app before the session counts, pass authorize to deviceSession: a refusal shows as not_authorized, in this component’s words or your errorMessage.
Native parts
Each part comes from @agentpost-tools/identityhound-ui/native.
EmailCodeSignInRoot: Runs the sign-in and holds what the principal types. Takes the props above; withoutidentity, it uses the provider’s.EmailCodeSignInTitle: The heading.EmailCodeSignInDescription: The words under the heading, often a function of the step.EmailCodeSignInEmailStep: Shown on the email step.EmailCodeSignInCodeStep: Shown on the code step.EmailCodeSignInSignedIn: Shown once the principal is signed in.EmailCodeSignInField: Holds a field (nameisemailorcode) and knows when the error is about it: its state hasinvalid.EmailCodeSignInEmailInput: The address: the email keyboard, saved addresses offered, and the keyboard’s send key sends the code.EmailCodeSignInCodeInput: One input for all 6 digits, which iOS and Android offer to fill in from the email. It keeps digits only and checks the code once the last one arrives. Draw the digits as boxes fromcodeValue, with this input over them, as the finished screen does.EmailCodeSignInFieldError: The error about its field, shown while there is one, in the error’s words unless you give content.EmailCodeSignInAlert: An error about the whole form, such asthrottled, shown while there is one, in the error’s words unless you give content.EmailCodeSignInSend: Sends a code. Disabled while a request is out.EmailCodeSignInVerify: Signs in with the typed code. Disabled while a request is out.EmailCodeSignInResend: Sends a new code. Disabled while a request is out and untilresendInreaches 0.EmailCodeSignInChangeEmail: Back to the email step, keeping the address. Disabled while the code is being checked.useEmailCodeSignInState: The sign-in’s state, for content of your own inside the root.
Every part takes its look the same way:
- It passes every prop to its React Native element, so
style,className(with NativeWind), andtestIDwork as usual. styleandchildrencan be functions of the part’s state: the sign-in’s state, plus what was typed (emailValue,codeValue),invalidon a field’s parts, andpressedanddisabledon a button.asChildrenders your own component, such as yourButtonorInput, in place of the part’s element, with the part’s behavior merged in: bothonPresshandlers run, and the styles stack.
The parts own what every app needs: labels and roles, disabled and busy states, the error read with its field, and announcements to the screen reader when a code is sent, when an error appears, and on sign-in. No part opens the keyboard until the principal taps a field.
Native apps have no agent actions: UI SDK’s agent bridge renders only to the web.