Sign in, accept an invitation and manage sessions.
import { Component } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { AuthScreen } from "./ui/uicontext/components/kit/Session.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, radius } from "./ui/uicontext/components/tokens.stylex.ts"import { PretendAuthServer } from "./server.ts"const styles = stylex.create({ frame: { inlineSize: "min(100%, 26rem)", blockSize: 560, overflow: "hidden", borderRadius: radius.lg, borderWidth: 1, borderStyle: "solid", borderColor: color.line },})const SignInNoDeps = Html.component({ name: "SignIn", model: Schema.Struct({}), message: Schema.Never,}).make({ init: () => ({}), update: ($) => $.model, view: (h) => h.div.attrs(sx(styles.frame)).children( AuthScreen(h, { props: { arrival: { _tag: "SignIn" }, claimed: true, methods: ["password", "link", "passkey"], copy: { signIn: { title: "Sign in to Northwind", lede: "Use your work email." }, emailPlaceholder: "[email protected]" }, }, }), ),})// the pretend server stands in for your auth routesexport const SignIn = SignInNoDeps.pipe(Component.provide(PretendAuthServer))Installation
pnpm dlx shadcn@latest add checkfu/uicontext/sessionUsage
import { AuthScreen, arrivalOf } from "./ui/uicontext/components/kit/Session.ts"export const SignInPage = <M>(h: Html.H<M>, link: { readonly join?: { readonly id: string; readonly code: string } }, claimed: boolean) => AuthScreen(h, { props: { arrival: arrivalOf(link), claimed, methods: ["password", "link"], }, })Examples
Joining from an invitation
The invitation is read first: the email it was sent to fills the form.
import { Component } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { AuthScreen, arrivalOf } from "./ui/uicontext/components/kit/Session.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, radius } from "./ui/uicontext/components/tokens.stylex.ts"import { PretendAuthServer } from "./server.ts"const styles = stylex.create({ frame: { inlineSize: "min(100%, 26rem)", blockSize: 520, overflow: "hidden", borderRadius: radius.lg, borderWidth: 1, borderStyle: "solid", borderColor: color.line },})const InvitationNoDeps = Html.component({ name: "JoinFromInvitation", model: Schema.Struct({}), message: Schema.Never,}).make({ init: () => ({}), update: ($) => $.model, view: (h) => h.div.attrs(sx(styles.frame)).children( AuthScreen(h, { props: { arrival: arrivalOf({ join: { id: "inv-42", code: "k3y" } }), claimed: true, copy: { join: { title: "Join Northwind", lede: "Ana invited you. Make your account to get in." } }, }, }), ),})export const JoinFromInvitation = InvitationNoDeps.pipe(Component.provide(PretendAuthServer))API reference
Props
| Name | Type | Description |
|---|---|---|
arrivalrequired | Arrival | — |
claimedrequired | boolean | — |
copy | AuthCopy | — |
tone | "accent" | "neutral" | The submit button: the accent (default), or solid neutral for apps that keep color for status |
paths | AuthPathOverrides | This screen's session routes, over the ones a component above provides with authPathsLayer |
methods | SignInMethod[] | How people may sign in, the first shown first; a password only by default |