Sign-in
Who is signed in, and the calls that sign people in, up and out. The ways in (password, sign-in links, Google) and who may sign up are set in app.config.ts auth; a role's profile table links each account to its row.
/signin is built in: it shows SignIn, which offers only the ways in the app keeps on. Write routes/signin.tsx to replace it with your own screen built on useAuth and useAuthOptions.
useAuth
useAuthfunction
Who is signed in (status: unknown until the browser has asked, then guest or user; user: { id, email, name, role, isAdmin? }) and the calls signIn(email, password), signUp({ name, email, password, role? }), requestSignInLink(email) and signOut(). Every read refreshes after a sign-in or sign-out.
useAuth(): { signIn: (email: string, password: string) => Promise<void>; signUp: (f: { name: string; email: string; password: string; role?: string | undefined; workspace?: string | undefined; }) => Promise<void>; requestSignInLink: (email: string) => Promise<void>; requestPasswordReset: (email: string) => Promise<void>; resetPassword: (token: string, newPassword: string) => Promise<void>; startProvider: (name: string, role?: string | undefined) => Promise<void>; signOut: () => Promise<void>; status: "unknown" | "guest" | "user"; user: User | null; }- Returns
{ status, user, signIn, signUp, requestSignInLink, signOut }.- Errors
- signIn rejects with the server's message on a wrong password, a lockout (429
RATE_LIMITED) or an account that needs a second step. - signUp rejects when sign-up is closed (
signup: "invite"), the role may not sign up, or the app needs the email confirmed first (the message says so).
- signIn rejects with the server's message on a wrong password, a lockout (429
- Permissions
- Sign-up is open only to the roles in app.config.ts
auth.signup.as.
const auth = useAuth();
if (auth.status === "unknown") return null;
return auth.user ? (
<button onClick={() => void auth.signOut()}>Sign out {auth.user.name}</button>
) : (
<Link to="/signin">Sign in</Link>
);Source: internal/kernel/appsdk/ui/app.tsx:620
Sign-in screen
useAuthOptionsfunction
How the app lets visitors in, for a sign-in screen you write: providers ([{ name, label }], e.g. Google), personas (the roles a visitor may sign up as), signupPolicy, password and magicLink (whether each way is on). null until loaded in the browser.
useAuthOptions(): AuthOptions | null- Returns
AuthOptions | null- Errors
- Does not throw.
- Permissions
- Public.
const options = useAuthOptions();
if (!options) return <h1>Sign in</h1>;
return options.providers.map((p) => <button key={p.name}>Continue with {p.label}</button>);Source: internal/kernel/appsdk/ui/app.tsx:659
<SignIn>component
The built-in sign-in form at /signin and on pages that need a signed-in user: email and password, a sign-in link by email and the providers, each only when the app keeps it on. next is where it goes once signed in.
SignIn({ next, mode }: { next?: string; mode?: SignInMode } = {}): ElementParameters
| Name | Type | Description |
|---|---|---|
{ next, mode }optional | { next?: string; mode?: SignInMode } |
- Returns
Element- Errors
- Does not throw.
- Permissions
- Public.
// routes/signin.tsx: your own page around the built-in form
import { SignIn, defineRoute } from "@appbricx/ui";
export const meta = defineRoute({ public: true, title: "Sign in" });
export default function SignInPage() {
return <div className="mx-auto max-w-sm"><Logo /><SignIn next="/bookings" /></div>;
}Source: internal/kernel/appsdk/ui/signin.tsx:47
Types
interface AuthState {
/** unknown until the browser has asked who is signed in. */
status: "unknown" | "guest" | "user";
user: User | null;
}Source: internal/kernel/appsdk/ui/app.tsx:46
interface User {
id: string;
email: string;
name: string | null;
role: string;
isAdmin?: boolean;
}Source: internal/kernel/appsdk/ui/app.tsx:38
interface AuthOptions {
providers: Array<{ name: string; label: string }>;
/** The personas a visitor may pick at sign-up, in the server's order. */
personas: string[];
signupPolicy: string;
/** Email + password sign-in and sign-up (off when app.config.ts auth.providers leaves "password" out). */
password: boolean;
/** Sign-in links by email (off when auth.providers leaves "magicLink" out). */
magicLink: boolean;
/** A team app's workspaces (app.config.ts). */
workspaces?: { label: string; signup: "own" | "invite" };
}Source: internal/kernel/appsdk/ui/app.tsx:73