# Memory adapter

> A complete auth backend in the browser for prototypes, demos and tests: sign-up, email codes, two-step, magic links, organizations.

Status: beta. Category: Auth.

```ts
import { Memory adapter } from '@glyphui/auth/memory'
```

Exports: `memoryAdapter`.

## Notes

- Passwords are stored in plain text. Never use it in production.
- persist: "local" keeps users and the session in localStorage, shared between tabs.
- fail lets an operation throw, to see error states: fail: (op) => op === "signIn" ? new AuthError("Down") : undefined.
- expireSession() revokes the session server-side, to try SessionExpiredDialog.

## Example: Prototype a full flow

Every screen works against it. "Emailed" codes appear as toasts here; by default they are logged to the console.

```tsx
import { AuthProvider, useAuth } from '@glyphui/auth'
import { memoryAdapter } from '@glyphui/auth/memory'
import { SignInForm } from '@glyphui/auth/ui'
import { Button, Text, toast } from '@glyphui/ui'

const adapter = memoryAdapter({
  latency: 500,
  users: [
    { email: 'ada@example.com', password: 'correct horse', name: 'Ada Lovelace' },
    { email: 'grace@example.com', password: 'cobol rules', name: 'Grace Hopper', twoFactor: true },
  ],
  onCode: ({ kind, email, code }) =>
    toast(`Email to ${email}`, { description: `${kind}: ${code}` }),
})

function Demo() {
  const { user, signOut } = useAuth()
  if (user)
    return (
      <div className="grid justify-items-center gap-3">
        <Text>Signed in as {user.name}.</Text>
        <Button variant="outline" onClick={() => signOut()}>
          Sign out
        </Button>
      </div>
    )
  return (
    <SignInForm
      headingLevel={3}
      description="Try ada@example.com / correct horse, or grace@example.com / cobol rules for two steps."
    />
  )
}

export default function Example() {
  return (
    <AuthProvider adapter={adapter} syncTabs={false}>
      <Demo />
    </AuthProvider>
  )
}
```

Live page: https://glyphui.xyz/components/auth-memory
