Session expired

Pro

The sign-in ran out while the app was open. It blocks the page (nothing behind it would work) but keeps it: signing in again returns you to the same place. Say what was kept only when the app really kept it.

Markdown

Preview

Install

With the Candor CLI

First time? Get started sets up the registry and theme. Or with shadcn directly: npx shadcn@latest add @candor/session-expired

Brings in: button, dialog, locale · npm: lucide-react@^1.67.0

Usage

TSX · The example above
"use client"

import * as React from "react"
import { SessionExpiredDialog } from "@/components/session-expired"
import { Button } from "@/components/ui/button"

export default function Example() {
  const [open, setOpen] = React.useState(false)
  const [signingIn, setSigningIn] = React.useState(false)
  const signIn = () => {
    setSigningIn(true)
    // Your sign-in flow goes here; this one just succeeds after a moment.
    window.setTimeout(() => {
      setSigningIn(false)
      setOpen(false)
    }, 1200)
  }
  return (
    <>
      <Button variant="outline" onClick={() => setOpen(true)}>
        End the session
      </Button>
      <SessionExpiredDialog
        open={open}
        email="sam@acme.example"
        kept="Your unsent message is kept."
        signingIn={signingIn}
        onSignIn={signIn}
        onSignOut={() => setOpen(false)}
      />
    </>
  )
}

<SessionExpiredDialog>

PropTypeDefaultDescription
openrequiredboolean—Whether the dialog is showing. It can't be dismissed; only signing in or out closes it.
emailrequiredstring—Who was signed in, so a different person doesn't carry on by mistake.
keptstring | undefined—What the app kept, e.g. "Your unsent message is kept." Omit if nothing is.
signingInboolean | undefinedfalseA sign-in is under way; the button waits and can't be pressed again. Defaults to false.
failedstring | undefined—Why the last sign-in attempt failed.
onSignInrequired() => void—Called when the person chooses to sign in again (or try again after a failure).
onSignOut(() => void) | undefined—Shows "Not you? Sign out"; called when it's pressed.

Strings

The fixed words, in English by default. Change any of them under sessionExpired in <LocaleProvider strings={{ … }}>; the table is exported as sessionExpiredStrings.

KeyEnglish
titleYour session has ended
signInAgainAsSign in again as {email} to carry on.
waitingWaiting for sign-in…
tryAgainTry again
signInAgainSign in again
notYouNot you? Sign out