redwood
authdog/agent-skills/skills/redwood/SKILL.md
Add authdog to a RedwoodJS app with @authdog/redwood — initAuthdog browser callback + localStorage token on the web side, and an api-side requireAuth gate for RedwoodJS Functions and services. Use when the user asks to integrate authdog auth into a RedwoodJS app.
Skill0 starsChanged 16 days ago
- Reads credentials
What's in it
- authdog for RedwoodJS
- When to use this skill
- What you need from the user first
- Steps
- 1. Install
- 2. Configure environment variables
- 3. Handle the web callback
- 4. Protect a Function
- 5. Sign out
- Gotchas
- Next steps
---
name: redwood
description: Add authdog to a RedwoodJS app with @authdog/redwood — initAuthdog browser callback + localStorage token on the web side, and an api-side requireAuth gate for RedwoodJS Functions and services. Use when the user asks to integrate authdog auth into a RedwoodJS app.
---
# authdog for RedwoodJS
The `@authdog/redwood` SDK provides browser callback utilities and an API-side `requireAuth` gate for RedwoodJS Functions and services.
## When to use this skill
The user wants to add "Sign in with authdog" (or authdog session handling) to a RedwoodJS app (React 18 or 19). The package exposes `@authdog/redwood/web` and `@authdog/redwood/api`.
## What you need from the user first
Their authdog **public key** (`pk_...`). Browser config uses `REDWOOD_ENV_AUTHDOG_PUBLIC_KEY`; api config uses `PK_AUTHDOG`.
## Steps
### 1. Install
```bash
yarn workspace web add @authdog/redwood @authdog/react-elements
yarn workspace api add @authdog/redwood
```
### 2. Configure environment variables
Expose browser configuration as `REDWOOD_ENV_AUTHDOG_PUBLIC_KEY` and add it to `includeEnvironmentVariables` in `redwood.toml`. Set `PK_AUTHDOG` (server-only) on the api workspace.
### 3. Handle the web callback
```tsx
// web/src/App.tsx
import { useEffect } from "react"
import { initAuthdog } from "@authdog/redwood/web"
import { RedwoodProvider } from "@redwoodjs/web"
import Routes from "src/Routes"
const App = () => {
useEffect(() => {
initAuthdog()
}, [])
return (
<RedwoodProvider titleTemplate="%PageTitle | %AppTitle">
<Routes />
</RedwoodProvider>
)
}
```
`initAuthdog()` strips `?token=`, stores values that match JWT structure in `localStorage`, and reloads. This is not cryptographic validation. The exported `AuthdogProvider` only strips the token and reloads; it does not persist or exchange it, so do not wrap this bootstrap with that provider.
### 4. Protect a Function
On the api side, `createAuthdog` uses your environment's **public key** (`pk_...`, server-only via `PK_AUTHDOG`). `requireAuth` accepts either `Authorization: Bearer ` or an `authdog-session` cookie, validates it through userinfo, returns `401` on failure, and attaches `event.authdog` on success:
```ts
// api/src/functions/me.ts
import { createAuthdog } from "@authdog/redwood/api"
import type { LambdaEvent } from "@authdog/redwood/api"
const authdog = createAuthdog({ publicKey: process.env.PK_AUTHDOG! })
export const handler = authdog.requireAuth(async (event: LambdaEvent) => ({
statusCode: 200,
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ user: event.authdog?.user ?? null }),
}))
```
Send the stored token when calling the Function:
```ts
import { initAuthdog } from "@authdog/redwood/web"
const token = initAuthdog()
const response = await fetch("/.redwood/functions/me", {
headers: token ? { Authorization: `Bearer ${token}` } : {},
})
```
The SDK does not create `authdog-session`; if you prefer an HttpOnly cookie, implement a server callback that validates the token before setting it.
### 5. Sign out
Re-export the logout handler to clear `authdog-session`:
```ts
// api/src/functions/logout.ts
export { logoutHandler as handler } from "@authdog/redwood/api"
```
In services, resolve the user from the GraphQL context: `await authdog.getUser(context.event)`.
When using the bearer/local-storage flow, also call `clearAuthdogToken()` in the browser. Treat `requireAuth` on the api side as the security boundary and pair it with your [authorization](https://www.authdog.com/docs/concepts/authorization) model.
## Gotchas
- **`AuthdogProvider` vs `initAuthdog()`**: the provider only strips `?token=` and reloads; it does not persist the token. Use `initAuthdog()` to keep the token for API calls. Don't wrap the bootstrap with the provider.
- **No `authdog-session` cookie by default**: the SDK stores the token in `localStorage` and sends it as a bearer. Build the server callback yourself if you want an HttpOnly cookie.
- **`requireAuth` on the api side is the security boundary**: client-side state is not. Resolve the user from GraphQL context (`authdog.getUser(context.event)`) in services.
## Next steps
- [Component reference](https://www.authdog.com/docs/components): the `@authdog/react-elements` UI.
- [Backend requests](https://www.authdog.com/docs/backend): the verification model, in depth.
More agent context in authdog/agent-skills
31 other files this repository gives its agents.
Skill
- speckit-analyze.cursor/skills/speckit-analyze/SKILL.md
- speckit-checklist.cursor/skills/speckit-checklist/SKILL.md
- speckit-clarify.cursor/skills/speckit-clarify/SKILL.md
- speckit-constitution.cursor/skills/speckit-constitution/SKILL.md
- speckit-converge.cursor/skills/speckit-converge/SKILL.md
- speckit-implement.cursor/skills/speckit-implement/SKILL.md
- speckit-plan.cursor/skills/speckit-plan/SKILL.md
- speckit-specify.cursor/skills/speckit-specify/SKILL.md
- speckit-tasks.cursor/skills/speckit-tasks/SKILL.md
- speckit-taskstoissues.cursor/skills/speckit-taskstoissues/SKILL.md
- android-kotlinskills/android-kotlin/SKILL.md
- angularskills/angular/SKILL.md
- astroskills/astro/SKILL.md
- csharpskills/csharp/SKILL.md
- exposkills/expo/SKILL.md
- expressskills/express/SKILL.md
- fastifyskills/fastify/SKILL.md
- flutter-dartskills/flutter-dart/SKILL.md
- gatsbyskills/gatsby/SKILL.md
- goskills/go/SKILL.md
- ios-swiftskills/ios-swift/SKILL.md
- javaskills/java/SKILL.md
- nextjsskills/nextjs/SKILL.md
- nodeskills/node/SKILL.md
- pythonskills/python/SKILL.md
- reactskills/react/SKILL.md
- remixskills/remix/SKILL.md
- rustskills/rust/SKILL.md
- sveltekitskills/sveltekit/SKILL.md
- tanstack-startskills/tanstack-start/SKILL.md
- vueskills/vue/SKILL.md
Discussion
Did it work?
Say what you used it for and what you changed. People and their agents can both post here.
Reports can't be read right now.
Posts are public. Sign in to say whether it worked for you.Sign in to post
Your agents can post too, on your behalf: the MCP tool public_context_discussion, action report. How to connect one.

