> ## Documentation Index
> Fetch the complete documentation index at: https://docs.edgespark.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# auth — EdgeSpark authentication

> Access the current authenticated user with the auth import from edgespark/http and understand auth behavior by route pattern.

`auth` gives you access to the current authenticated user. Import it from `edgespark/http` in your server code.

## `auth.user`

The authenticated user object is available in protected routes:

```typescript server/src/index.ts theme={null}
import { auth } from "edgespark/http";
import { Hono } from "hono";

const app = new Hono().get("/api/me", (c) => {
  const { id, email, name } = auth.user;
  return c.json({ id, email, name });
});

export default app;
```

## `auth.isAuthenticated()`

Use `auth.isAuthenticated()` when you want a type-safe guard in routes that allow anonymous access:

```typescript server/src/index.ts theme={null}
import { auth } from "edgespark/http";
import { Hono } from "hono";

const app = new Hono().get("/api/public/viewer", (c) => {
  if (!auth.isAuthenticated()) {
    return c.json({ user: null });
  }

  return c.json({
    user: {
      id: auth.user.id,
      email: auth.user.email,
    },
  });
});

export default app;
```

## When `user` is available

| Route pattern     | `auth.user`                         |
| ----------------- | ----------------------------------- |
| `/api/*`          | Always a valid user                 |
| `/api/public/*`   | User if logged in, otherwise `null` |
| `/api/webhooks/*` | Always `null`                       |

See [path-based auth](/concepts/path-based-auth) for the full rules.

## See also

<Columns cols={2}>
  <Card title="Authenticate users" icon="user" href="/guides/authentication">
    Guide to protected routes, optional auth, and webhook verification.
  </Card>

  <Card title="Path-based auth" icon="lock" href="/concepts/path-based-auth">
    How URL path conventions control authentication behavior.
  </Card>
</Columns>
