# Auth Concept

import { Callout } from "fumadocs-ui/components/callout";
import { Tabs, Tab } from "fumadocs-ui/components/tabs";
import { Step, Steps } from "fumadocs-ui/components/steps";
import {
  Badge,
  Card,
  CardContent,
  CardHeader,
  CardTitle,
} from "@pycolors/ui";
import {
  ArrowRight,
  CheckCircle,
  XCircle,
} from "lucide-react";
import { PreferAvoid } from '@/components/docs/prefer-avoid';

<div className="flex flex-wrap items-center gap-2">
  <Badge variant="outline">
    Starter
  </Badge>

  <Badge>
    Auth
  </Badge>
</div>

## Overview

Authentication is the **entry point of every SaaS product**.

Starter Free gives you a complete **authentication surface**:

* login
* register
* forgot password
* validation
* loading states
* error states
* redirect flows

But **no provider is wired**.

This is intentional.

<Callout title="Core idea">
  Starter Free defines the **auth UX contract**.
  You plug in the provider when your product becomes real.
</Callout>

## Mental model

> Auth UI is stable.
> Auth implementation is replaceable.

| Layer           | Responsibility                      |
| --------------- | ----------------------------------- |
| UI              | Forms, states, validation, feedback |
| Routing         | Redirects, protected pages          |
| Provider        | Sessions, tokens, identity          |
| Backend (later) | permissions, roles, access control  |

## What Starter Free gives you

<PreferAvoid
  preferTitle="Included"
  avoidTitle="Not included (on purpose)"
  prefer={[
  'login / register / forgot password screens',
  'form validation and error states',
  'loading and disabled states',
  'redirect flows',
  'AuthShell layout',
]}
  avoid={[
  'session management',
  'JWT / cookies',
  'OAuth providers',
  'email delivery',
  'password reset backend',
]}
/>

## Auth routes

```txt title="routes"
app/(auth)/
  login/
  register/
  forgot-password/
```

## AuthShell pattern

```tsx title="components/auth/auth-shell.tsx"
<AuthShell
  title="Welcome back"
  description="Sign in to your account"
  footer={...}
/>
```

## Flows

<Tabs items={["Login", "Register", "Forgot password"]}>
  <Tab value="Login">
    ```txt
    User submits form
    → validate inputs
    → call signIn()
    → redirect to /dashboard
    ```
  </Tab>

  <Tab value="Register">
    ```txt
    User creates account
    → validate inputs
    → call signUp()
    → redirect to /dashboard
    ```
  </Tab>

  <Tab value="Forgot password">
    ```txt
    User submits email
    → always show success state
    → never reveal if email exists
    ```
  </Tab>
</Tabs>

## Wiring your provider

Starter Free is provider-agnostic:

* Auth.js / NextAuth
* Clerk
* Supabase Auth
* Custom backend

```tsx title="auth-action.ts"
async function onSubmit(values) {
  await signIn(values.email, values.password);
  router.push("/dashboard");
}
```

## UX rules

<PreferAvoid
  prefer={[
  'clear error messages',
  'disabled submit while loading',
  'consistent redirects',
  'explicit success states',
]}
  avoid={[
  'generic errors',
  'double submissions',
  'no feedback states',
  'leaking user existence',
]}
/>