Skip to content
Vertical Jump Designs-uiFront-End Studio
Get Pro

v3.9 is out.

Templates

Sign in

Free

A centered sign-in card with inline errors, a password reset link and a link to sign up.

Open full screen

The download follows the framework picked above the code. Unzip it and run npm install, then npm run dev.

Live preview

Preview width

Code

tsx
import { useState, type FormEvent } from "react";
import {
  Box,
  Button,
  Card,
  CheckBox,
  Divider,
  Field,
  Flex,
  Heading,
  Input,
  Link,
  PasswordInput,
  Stack,
  Text,
} from "@vjdesigns/vjdesigns-ui";

/** A centered sign-in card: email and password with inline errors, "keep me signed in", a reset link and a link to sign up. Connect `signIn` to your auth provider. */
export function SignInPage() {
  const [errors, setErrors] = useState<{ email?: string; password?: string }>({});
  const [status, setStatus] = useState("");

  function signIn(event: FormEvent<HTMLFormElement>) {
    event.preventDefault();
    const data = new FormData(event.currentTarget);
    const email = String(data.get("email") ?? "").trim();
    const password = String(data.get("password") ?? "");
    const next = {
      email: !email ? "Enter your email address." : !email.includes("@") ? "Enter an email address like name@example.com." : undefined,
      password: !password ? "Enter your password." : undefined,
    };
    setErrors(next);
    setStatus(next.email || next.password ? "" : "Signed in. Replace this with a redirect to your app.");
  }

  return (
    <Box as="main" minHeight="100vh" display="flex" surface="sunken" px={4} py={10} style={{ alignItems: "center", justifyContent: "center" }}>
      <Card variant="elevated" padding="lg" style={{ width: "100%", maxWidth: "26rem" }}>
        <Stack gap={6}>
          <Stack gap={2}>
            <Text weight="black" size="lg">
              Acme
            </Text>
            <Heading level={1} size="2xl">
              Sign in to your account
            </Heading>
            <Text tone="muted">
              New here? <Link href="#sign-up">Create an account</Link>
            </Text>
          </Stack>

          <form onSubmit={signIn} noValidate>
            <Stack gap={4}>
              <Field label="Email" error={errors.email} required>
                <Input name="email" type="email" autoComplete="email" fullWidth />
              </Field>
              <Field label="Password" error={errors.password} required labelAction={<Link href="#reset">Forgot password?</Link>}>
                <PasswordInput name="password" autoComplete="current-password" fullWidth />
              </Field>
              <CheckBox name="remember" label="Keep me signed in" />
              <Button type="submit" tone="primary" fullWidth>
                Sign in
              </Button>
            </Stack>
          </form>

          <Text role="status" size="sm" weight="semibold">
            {status}
          </Text>

          <Divider />
          <Flex justify="center" gap={4} wrap="wrap">
            <Link href="#terms" size="sm" variant="subtle">
              Terms
            </Link>
            <Link href="#privacy" size="sm" variant="subtle">
              Privacy
            </Link>
            <Link href="#help" size="sm" variant="subtle">
              Help
            </Link>
          </Flex>
        </Stack>
      </Card>
    </Box>
  );
}