SignIn
Signing in, the whole way: email and password, the code of a second factor, a passkey, and a forgotten password. One frame for every step, and one task per step.
import { AuthLayout } from '@sypnia/ui/react'
On a desktop
Type any email and password: «wrong» as the password shows what happens when they do not match, then any code but 000000 signs you in. Try «Forgot your password?» too.
Sign in to Sypnia
Use the email you signed up with.
New to Sypnia? Create an account
Code
import { useState, type ReactNode } from 'react';
import {
Alert, AuthLayout, Button, Divider, EmailInput, Field, Form, FormActions, List, ListItem, Notice, OtpInput,
PasswordInput, Says, SkeletonOf, Stack, useSypnia, type FormProblem,
} from '@sypnia/ui/react';
// Sign in, the whole flow: email and password, the code of a second factor, a passkey, and «Forgot your password?»
// with its email. Every step is the same frame; when the step changes, the focus moves to its title.
const en = {
signIn: 'Sign in to Sypnia', signInLead: 'Use the email you signed up with.',
email: 'Email', password: 'Password', forgot: 'Forgot your password?', submit: 'Sign in', busy: 'Signing in…',
or: 'or', passkey: 'Sign in with a passkey', newHere: 'New to Sypnia?', create: 'Create an account',
noEmail: 'Write your email.', badEmail: 'Write a whole email address, like ana@northwind.io.', noPassword: 'Write your password.',
mismatch: 'That email and password do not match. Check both, or reset your password.',
code: 'Enter your code', codeLead: 'Open your authenticator app and type the 6-digit code it shows for Sypnia.',
codeLabel: 'Code from your app', wrongCode: 'That code is not right, or it already changed. Type the one your app shows now.',
useOther: 'Use another way', back: 'Back to sign in',
reset: 'Reset your password', resetLead: 'We will email you a link to choose a new one.', sendLink: 'Email me a link', sending: 'Sending…',
sent: 'Check your email', sentLead: (e: string) => `If ${e} has an account, a link to choose a new password is on its way. It works for 30 minutes.`,
resend: 'Send it again', resent: 'Sent again. Look in your spam folder too.',
done: 'You are signed in', doneLead: 'Taking you to your projects.', open: 'Go to my projects',
down: 'Sign-in is not answering', downBody: 'Your data is safe. This usually clears up in a minute.', retry: 'Try again',
asideSays: 'Your tables, your API, in your region.', perks: ['Postgres with an API from the first minute', 'Backups every day, kept for 30 days', 'Free to run on your own servers'],
terms: 'Terms', privacy: 'Privacy', help: 'Help',
};
const es: typeof en = {
signIn: 'Inicia sesión en Sypnia', signInLead: 'Usa el correo con el que te registraste.',
email: 'Correo', password: 'Contraseña', forgot: '¿Olvidaste tu contraseña?', submit: 'Iniciar sesión', busy: 'Iniciando sesión…',
or: 'o', passkey: 'Iniciar sesión con una llave de acceso', newHere: '¿Eres nuevo en Sypnia?', create: 'Crea una cuenta',
noEmail: 'Escribe tu correo.', badEmail: 'Escribe un correo completo, como ana@northwind.io.', noPassword: 'Escribe tu contraseña.',
mismatch: 'Ese correo y esa contraseña no coinciden. Revisa los dos, o restablece tu contraseña.',
code: 'Escribe tu código', codeLead: 'Abre tu app de autenticación y escribe el código de 6 dígitos que muestra para Sypnia.',
codeLabel: 'Código de tu app', wrongCode: 'Ese código no es correcto, o ya cambió. Escribe el que muestra tu app ahora.',
useOther: 'Usar otra forma', back: 'Volver a iniciar sesión',
reset: 'Restablece tu contraseña', resetLead: 'Te enviamos un enlace para elegir una nueva.', sendLink: 'Enviarme un enlace', sending: 'Enviando…',
sent: 'Revisa tu correo', sentLead: (e: string) => `Si ${e} tiene una cuenta, va en camino un enlace para elegir una contraseña nueva. Sirve por 30 minutos.`,
resend: 'Enviarlo de nuevo', resent: 'Enviado de nuevo. Mira también en la carpeta de spam.',
done: 'Ya iniciaste sesión', doneLead: 'Te llevamos a tus proyectos.', open: 'Ir a mis proyectos',
down: 'El inicio de sesión no responde', downBody: 'Tus datos están a salvo. Esto suele resolverse en un minuto.', retry: 'Intentar de nuevo',
asideSays: 'Tus tablas, tu API, en tu región.', perks: ['Postgres con API desde el primer minuto', 'Copias de seguridad cada día, guardadas 30 días', 'Gratis en tus propios servidores'],
terms: 'Términos', privacy: 'Privacidad', help: 'Ayuda',
};
const wait = (ms: number) => new Promise((r) => setTimeout(r, ms));
type Step = 'password' | 'code' | 'reset' | 'sent' | 'done';
export default function SignIn({ state = 'ready' }: { state?: 'ready' | 'loading' | 'error' }) {
const { locale } = useSypnia();
const c = locale.startsWith('es') ? es : en;
const [step, setStep] = useState<Step>('password');
const [email, setEmail] = useState('');
const [problems, setProblems] = useState<FormProblem[]>([]);
const [codeError, setCodeError] = useState<string>();
const [checking, setChecking] = useState(false);
const [resent, setResent] = useState(false);
const [down, setDown] = useState(state === 'error');
// Loading: while the app checks for a session, the real page with its words; the fields and buttons wait in their
// own boxes, so that if there is no session nothing moves.
const loading = state === 'loading';
const wait = (n: ReactNode) => (loading ? <SkeletonOf>{n}</SkeletonOf> : n);
const check = (v: FormData): FormProblem[] => {
const e = String(v.get('email') ?? '').trim(), out: FormProblem[] = [];
if (!e) out.push({ name: 'email', label: c.email, message: c.noEmail });
else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)) out.push({ name: 'email', label: c.email, message: c.badEmail });
if (step === 'password' && !String(v.get('password') ?? '')) out.push({ name: 'password', label: c.password, message: c.noPassword });
return out;
};
const verify = async (code: string) => {
setChecking(true); setCodeError(undefined);
await wait(700);
setChecking(false);
if (code === '000000') setCodeError(c.wrongCode); else setStep('done');
};
const back = <Button variant="quiet" icon="arrow-left" onClick={() => { setStep('password'); setProblems([]); }}>{c.back}</Button>;
const view: Record<Step, { title: string; lead: string; body: ReactNode }> = {
password: {
title: c.signIn, lead: c.signInLead,
body: (
<Stack gap={5}>
{down && <Alert tone="fail" title={c.down} actions={<Button size="sm" icon="refresh" onClick={() => setDown(false)}>{c.retry}</Button>}>{c.downBody}</Alert>}
<Form label={c.signIn} validate={check} problems={problems} onSubmit={async (v) => {
setEmail(String(v.get('email')));
await wait(900);
if (v.get('password') === 'wrong') setProblems([{ name: 'password', label: c.password, message: c.mismatch }]);
else setStep('code');
}}>
{({ errorFor }) => (
<>
<Field label={c.email} error={errorFor('email')}>{wait(<EmailInput name="email" defaultValue={email} autoComplete="username" disabled={down} />)}</Field>
<Field label={c.password} error={errorFor('password')}>{wait(<PasswordInput name="password" autoComplete="current-password" disabled={down} onChange={() => setProblems([])} />)}</Field>
<div>{wait(<Button variant="quiet" size="sm" onClick={() => setStep('reset')}>{c.forgot}</Button>)}</div>
{wait(<FormActions submitLabel={c.submit} busyLabel={c.busy} />)}
</>
)}
</Form>
<Divider label={c.or} />
{wait(<Button icon="fingerprint" block disabled={down} onClick={() => setStep('done')}>{c.passkey}</Button>)}
</Stack>
),
},
code: {
title: c.code, lead: c.codeLead,
body: (
<Stack gap={5}>
<Field label={c.codeLabel} error={codeError}><OtpInput autoFocus disabled={checking} onComplete={verify} /></Field>
{checking && <Notice tone="info" icon="shield">{c.busy}</Notice>}
{back}
</Stack>
),
},
reset: {
title: c.reset, lead: c.resetLead,
body: (
<Form label={c.reset} validate={check} onSubmit={async (v) => { setEmail(String(v.get('email'))); await wait(800); setResent(false); setStep('sent'); }}>
{({ errorFor }) => (
<>
<Field label={c.email} error={errorFor('email')}><EmailInput name="email" defaultValue={email} autoComplete="username" /></Field>
<FormActions submitLabel={c.sendLink} busyLabel={c.sending} cancel={back} />
</>
)}
</Form>
),
},
sent: {
title: c.sent, lead: c.sentLead(email),
body: (
<Stack gap={4}>
{resent && <Notice tone="ok">{c.resent}</Notice>}
<Button icon="mail" disabled={resent} onClick={() => setResent(true)}>{c.resend}</Button>
{back}
</Stack>
),
},
done: { title: c.done, lead: c.doneLead, body: <Button variant="primary" iconEnd="arrow-right" href="#projects">{c.open}</Button> },
};
const v = view[step];
return (
<AuthLayout title={v.title} lead={v.lead} brandHref="#"
after={step === 'password' ? <>{c.newHere} <a href="#sign-up">{c.create}</a></> : undefined}
aside={<><Says size="lg">{c.asideSays}</Says><List label={c.asideSays}>{c.perks.map((p) => <ListItem key={p} icon="check" title={p} />)}</List></>}
footer={<><a href="#terms">{c.terms}</a><a href="#privacy">{c.privacy}</a><a href="#help">{c.help}</a></>}>
{v.body}
</AuthLayout>
);
} On a phone
The same flow at 390 px: the card becomes the page and the side panel goes.
Skeleton
While the app checks whether there is a session already: the real page with its words; the fields and buttons wait in their own boxes.
Sign in to Sypnia
Use the email you signed up with.
New to Sypnia? Create an account
When sign-in is not answering
The service is down: the form stays, disabled, under a message that says what happened and lets the person try again.
Sign in to Sypnia
Use the email you signed up with.
Sign-in is not answering
New to Sypnia? Create an account
When to use it
Use it when
- The way into any Sypnia console, and into apps built on Sypnia Data.
- Errors that say which field to fix: an email that does not look like one, a password that does not match. Never which of the two was wrong, so nobody learns whether an account exists.
Do not use it when
- Asking for anything else on this page: the name, the plan and the team belong to sign-up and onboarding.
- Saying «this email has no account» after a reset request: the answer is the same for every address.
For everyone
- Each step is one heading; when the step changes the focus moves to it, so a screen reader reads where the person is.
- The fields say what they hold to password managers (
autocomplete="username",current-password). - The code boxes read as one field; pasting the code fills every box, and the code is checked as soon as the last box is filled.
- The side panel only says what the person gets: it is hidden on narrow screens and nothing in it is needed to sign in.
Props
| AuthLayout | Type | Default |
|---|---|---|
afterOne line under the card: «New to Sypnia? Create an account». | ReactNode | |
asideBeside the card when the layout is wide enough (60rem and more): what the person gets, a quote. Hidden on narrower screens, so nothing in it may be needed to finish the task. | ReactNode | |
brandThe mark at the top. Defaults to the Sypnia logo. | ReactNode | |
brandHrefWhere the mark leads. Without it the mark is not a link. | string | |
className | string | |
footerThe bottom line: terms, privacy, help. | ReactNode | |
leadOne sentence under the title: what happens here, or what to do next. | ReactNode | |
plainNo card around the content: for error and not-found pages, which say one thing and offer a way out. | boolean | |
titleWhat this step is, in the voice: «Sign in to Sypnia», «Check your email». It is the page's only h1. | ReactNode | |
topThe end of the top bar: a LanguageSwitch, a way back to the site. | ReactNode | |
width`sm` (26rem) for one or two fields, `md` (34rem) for longer forms and step-by-step tasks. | "sm" | "md" | sm |