Sina UI

Blocks

Auth

The screens every account needs: sign in, sign up, forgot and reset password, and a code check. Each takes your own async function, shows every state (checking, mistakes in the form, a refusal from your server, success) and works with password managers.

Examples

Sign in

The demo password is astrolabe; any other is refused, to show the message. The provider button and links are placeholders.

Sign in

Welcome back to Bayt al-Hikma.

or
<script lang="ts">
	import { GoogleIcon } from '@hugeicons/core-free-icons';
	import SignIn from '#lib/blocks/auth/SignIn.svelte';
	import { toast } from '#lib/ui/toast/index.js';

	// Stands in for your API. The demo password is "astrolabe"; anything else is refused with a code.
	async function signIn({ password }: { email: string; password: string; remember: boolean }) {
		await new Promise((r) => setTimeout(r, 800));
		if (password !== 'astrolabe') throw Object.assign(new Error(), { code: 'invalid_credentials' });
	}
</script>

<SignIn
	onsubmit={signIn}
	providers={[{ id: 'google', label: 'Google', icon: GoogleIcon }]}
	onprovider={(id) => toast(`This would go to ${id} to sign in.`)}
	forgotHref="#forgot"
	signUpHref="#sign-up"
	description="Welcome back to Bayt al-Hikma."
/>

Sign up

The password shows its strength as you type. ibnsina@baytalhikma.org is taken, to show a refusal from the server under its field.

Create an account

A reader’s card for the House of Wisdom.

At least 10 characters.

<script lang="ts">
	import SignUp from '#lib/blocks/auth/SignUp.svelte';

	// Stands in for your API: one address is already taken, to show the message.
	async function signUp({ email }: { name: string; email: string; password: string }) {
		await new Promise((r) => setTimeout(r, 900));
		if (email.toLowerCase() === 'ibnsina@baytalhikma.org')
			throw Object.assign(new Error(), { code: 'email_taken' });
	}
</script>

<SignUp
	onsubmit={signUp}
	termsHref="#sign-up"
	signInHref="#sign-in"
	description="A reader’s card for the House of Wisdom."
/>

Your API's own words

For an API that owns the password rule and writes its own messages: no length rule here, and any password under 12 characters is refused in the server's words.

Join the reading room

Your card works in every branch.

<script lang="ts">
	import SignUp from '#lib/blocks/auth/SignUp.svelte';
	import { UserFacingError } from '#lib/blocks/auth/errors.js';

	// Stands in for an API that owns the password rule and words its own errors for people.
	async function signUp({ password }: { name: string; email: string; password: string }) {
		await new Promise((r) => setTimeout(r, 600));
		if (password.length < 12)
			throw new UserFacingError('Check the password, then try again.', {
				password: 'Use 12 characters or more.'
			});
	}
</script>

<SignUp
	onsubmit={signUp}
	minLength={0}
	title="Join the reading room"
	description="Your card works in every branch."
/>

Forgot password

Send the link, then it says where it went. Sending again waits out a short countdown.

Reset your password

We’ll email you a link to choose a new one.

<script lang="ts">
	import ForgotPassword from '#lib/blocks/auth/ForgotPassword.svelte';

	// Stands in for your API.
	const send = () => new Promise((r) => setTimeout(r, 800));
</script>

<ForgotPassword onsubmit={send} signInHref="#sign-in" cooldown={30} />

Reset password

Type the new password twice; they must match.

Choose a new password

You’ll use it to sign in from now on.

At least 10 characters.

<script lang="ts">
	import ResetPassword from '#lib/blocks/auth/ResetPassword.svelte';

	// Stands in for your API, which also checks the reset token from the link.
	const save = () => new Promise((r) => setTimeout(r, 900));
</script>

<ResetPassword onsubmit={save} signInHref="#sign-in" />

Verification code

The demo code is 314159. It checks itself once the last digit is in; a wrong code is cleared, ready to try again.

Enter the code

We sent a 6-digit code to maryam@baytalhikma.org.

Didn’t get it? Send again in 30 seconds

<script lang="ts">
	import VerifyCode from '#lib/blocks/auth/VerifyCode.svelte';

	// Stands in for your API. The demo code is 314159; any other is refused with a code.
	async function check(code: string) {
		await new Promise((r) => setTimeout(r, 700));
		if (code !== '314159') throw Object.assign(new Error(), { code: 'invalid_code' });
	}
	const resend = () => new Promise((r) => setTimeout(r, 600));
</script>

<VerifyCode onsubmit={check} onresend={resend} sentTo="maryam@baytalhikma.org" cooldown={30} />

Installation

npx sinaui add blocks/auth

Errors from your server

Throw an Error with a code from any callback and the block shows it in plain words, under the field it's about when there is one. Unknown codes show “Something went wrong. Try again.”, never the raw error. The wording lives in errors.ts.

CodeShown
invalid_credentialsAbove the form
email_takenUnder the email
weak_passwordUnder the password
invalid_code, code_expiredUnder the code
link_expired, too_many_attemptsAbove the form

When your API's messages are already written for people

Throw a UserFacingError from errors.ts instead: new UserFacingError(message, fields). The message shows above the form and each entry of fields (field name → message) under its field, word for word. Only build it from your API's user-facing copy, never from a caught exception; any other error still shows the plain message above.

Props

SignIn

PropTypeDefault
onsubmit({ email, password, remember }) => Promise (required)
providers{ id, label, icon? }[][]
onprovider(id) => void
rememberboolean: shows “Keep me signed in”; without it, remember is falsetrue
forgotHref, signUpHrefstring
title, descriptionstring'Sign in', 'Welcome back.'

SignUp

PropTypeDefault
onsubmit({ name, email, password }) => Promise (required)
termsHrefstring: adds a terms box to tick
minLengthnumber: 0 leaves the length rule to your API10
providers, onprovider, signInHrefas SignIn

ForgotPassword

PropTypeDefault
onsubmit(email) => Promise (required)
cooldownnumber: seconds before sending again60
signInHrefstring

ResetPassword

PropTypeDefault
onsubmit(password) => Promise (required)
minLengthnumber: 0 leaves the length rule to your API10
signInHrefstring

VerifyCode

PropTypeDefault
onsubmit(code) => Promise (required)
onresend() => Promise
sentTostring: where the code went
length, cooldownnumber6, 60

Accessibility

  • Real forms with the right autocomplete on every field, so password managers fill them and SMS codes autofill.
  • Mistakes are joined to their field and read out; the first one gets focus on submit.
  • Refusals and success are announced; after a success, focus moves to the message.
  • Forgot password never says whether an account exists, so the form can't be used to find out.
  • The resend countdown is read as seconds, not a ticking clock.
  • With reduced motion, the confirmations appear without rising in.
Introduction
Theming
Changelog
Button
Action button
Confirm button
Copy button
Hold to confirm
Split button
Theme toggle
Calendar
Checkbox
Color picker
Combobox
Date picker
Date range picker
File drop
Form
Input
Mention input
Multi select
Number field
OTP input
Password input
Phone input
Radio cards
Radio group
Rich text editor
Search field
Segmented control
Select
Signature pad
Slider
Switch
Tag input
Upload
Wheel picker
Textarea
Time field
Toggle group
Toolbar
Alert dialog
Command palette
Context menu
Dialog
Drawer
Account menu
Dropdown
Hover card
Popover
Tooltip
Announcement bar
Alert
Empty state
Meter
Progress
Rolling number
Skeleton
Spinner
Toast
Avatar
Avatar group
Badge
Card
Carousel
Chart
Sparkline
World map
Chat
Code block
Data table
Folder
Kbd
Mind map
Resizable panels
Scroll area
Separator
Sortable
Table
Tag group
Virtual list
Audio player
Image
Image compare
Video
Visualizer
Breadcrumb
File tree
Docs navigation
Menubar
Navigation menu
Pagination
Sidebar layout
Stat tabs
Stepper
Tabs
Table of contents
Alarm clock
Clock
Dynamic island
Fluid orb
Hourglass
Stopwatch
Timer
AI chat
AI media
Auth
Board
Booking
Dashboard
Docs
File explorer
Messaging
Notifications
Settings
Studio
Team
Overview
Pricing
Agent chat
Calendar
Voice agent
Mail inbox
CMS
Blog
Marketing site
E-commerce
AI agents
SaaS landing page
SaaS app
Accordion
Dark theme
Light theme