Recipes
Login
The sign-in page with a one-time code step, its pending and error states, and what it does on a phone.
The sign-in page is a layout and a card. The card is controlled by your app: you say when it is signing in, what went wrong, and when to ask for the code.
Sign in with a one-time code
LoginLayout is the page (the ink side and the form side, with BrandMark as its brand), LoginCard the form, and "Forgot password?" a TextLink. Submitting sets pending; a wrong password comes back as error; a right one moves step to otp, and the otp props drive the code step (its own pending and error, resend, back). Try any email with the password "trndr", then the code 123456.
Pinned to TRNDR presetPR theme
Code
import { useState } from 'react';
import { BrandMark, Button, EmptyView, LoginCard, LoginLayout, TextLink, type LoginValue } from '@ergasti/bricks';
function SignIn() {
const [step, setStep] = useState<'credentials' | 'otp'>('credentials');
const [pending, setPending] = useState(false);
const [error, setError] = useState<string | null>(null);
const [codePending, setCodePending] = useState(false);
const [codeError, setCodeError] = useState<string | null>(null);
const [email, setEmail] = useState('');
const [done, setDone] = useState(false);
const signIn = (value: LoginValue) => {
setPending(true); setError(null); setEmail(value.email);
window.setTimeout(() => {
setPending(false);
if (value.password === 'trndr') setStep('otp');
else setError('The email or password is wrong.');
}, 800);
};
const verify = (code: string) => {
setCodePending(true); setCodeError(null);
window.setTimeout(() => {
setCodePending(false);
if (code === '123456') setDone(true);
else setCodeError('That code is wrong or expired. Check the last message we sent.');
}, 800);
};
return (
<LoginLayout landmark="div" brand={<BrandMark name="TRNDR" accent="." />} footer="© TRNDR 2026">
{done ? (
<EmptyView title="You are signed in" action={<Button onClick={() => { setDone(false); setStep('credentials'); }}>Start again</Button>}>{email} would now land on the PR portal.</EmptyView>
) : (
<LoginCard
defaultEmail="mona@trndr.co" pending={pending} error={error} step={step} onSubmit={signIn}
forgotPassword={<TextLink href="#reset">Forgot password?</TextLink>}
languageToggle={<Button size="sm" variant="ghost">عربي</Button>}
footnote="Brand accounts open the Brand portal. TRNDR team accounts open the PR portal."
otp={{
destination: '+20 10•• ••• 471', pending: codePending, error: codeError, onSubmit: verify,
onResend: () => setCodeError(null), onBack: () => { setStep('credentials'); setCodeError(null); },
}}
/>
)}
</LoginLayout>
);
}Steps
- Lay out the page. LoginLayout draws the ink side (your
brand, aheadline,text, afooter) and the form side. BrandMark is the sidebar's brand mark on its own, for thebrandslot (accentdraws the lime "."). It is the page's<main>by default; uselandmark="div"inside a page that already has one. - Ask for email and password. LoginCard calls
onSubmitwith the trimmed email, the password and "keep me signed in". AddforgotPassword(your link, a TextLink with your resethref),languageToggleand afootnote. - Sign in. Set
pendingwhile the request runs (the button reads "Signing in…" and is disabled). On a refusal, passerror; it shows as an alert above the fields. - Ask for the code. Set
step="otp"and pass the code step's props inotp: where the code went (destination, masked by your server),onSubmit(code),onResend(with a countdown,resendAfter),onBack,pendinganderror. OtpStep is the same step on its own. - Land. On success your app redirects; the card has nothing more to do.
Notes
- Under 860px the layout stacks: the ink side becomes a short band on top (the headline smaller, the text and footer hidden) and the form follows it, so a phone shows the form without scrolling past artwork.
- Paste works in the code boxes: a pasted code fills every box. With
autoSubmit(the default) the last digit submits. - The card never stores the password; it is only in the
onSubmitvalue.
Related: LoginCard, LoginLayout, OtpStep.