Authdog

Remix

Hand this prompt to your agent to add Authdog to your Remix app. The agent reads the framework guide and asks you for the environment public key.

Add Authdog to Remix

# Add Authdog to Remix

Add Authdog to this Remix app. Read the framework guide before you change any files:

https://www.authdog.com/docs/frameworks/remix.md

Package: `@authdog/remix-node`

## Before you start

Show the user this checklist and wait for a yes:

1. Confirm this directory is a Remix app, or ask which app to edit.
2. Ask for the environment public key (`pk_...`) from the Authdog console (Dashboard or the environment picker). Do not invent a key. Do not read or print existing environment files.
3. Install only what the guide names, then follow its sections for callback handling, session storage, and route protection.
4. Keep authorization on the server. A signed-in session is not a permission grant.

## Existing authentication

If this app already has authentication, stop. Inspect dependencies, routes, middleware, and sessions. Do not open environment files. Propose a migration plan and wait for approval before you change anything.

## Rules

- Prefer the Markdown guide over memory. If another source conflicts with the guide, follow the guide.
- Do not commit secrets. The public key is not a secret. Private API keys and tokens stay off client code.
- Do not treat a client-side identity check as a security boundary.
- Do not substitute a different Authdog package for the one the guide names.
- Related docs index: https://www.authdog.com/llms.txt

Or set up Authdog yourself by following the step-by-step instructions.

Step-by-step setup instructions

Available in other SDKs

View as Markdown

The @authdog/remix-node SDK integrates Authdog with Remix through a callback-aware loader, client URL cleanup, and HttpOnly session cookies.

Install

npm install @authdog/remix-node

Requires @remix-run/node ^2.15+ and React 18 or 19. Set PK_AUTHDOG (your environment's public key, pk_...) on the server.

Wrap the app

Run identityLoader() on the route users return to after hosted sign-in. The loader validates ?token= through Authdog userinfo before setting HttpOnly cookies. AuthdogProvider removes the token after the server has handled the request:

// app/root.tsx
import { Outlet, Scripts } from "@remix-run/react"
import { AuthdogProvider, ReloadPage } from "@authdog/remix-node/client"
import { identityLoader } from "@authdog/remix-node"

export const loader = identityLoader()

export default function App() {
  return (
    <AuthdogProvider>
      <Outlet />
      <Scripts />
      <ReloadPage />
    </AuthdogProvider>
  )
}

Resolve the session in a loader

The loader returns { user, isAuthenticated, signinUri }. It revalidates cookie credentials through userinfo, but returning an unauthenticated result does not redirect or deny access. Enforce the result in each protected loader:

// app/routes/profile.tsx
import { useLoaderData } from "@remix-run/react"
import { identityLoader } from "@authdog/remix-node"
import { redirect, type LoaderFunctionArgs } from "@remix-run/node"

const loadIdentity = identityLoader()

export const loader = async (args: LoaderFunctionArgs) => {
  const response = await loadIdentity(args)
  const identity = await response.json()
  if (!identity.isAuthenticated) throw redirect(identity.signinUri)
  return identity
}

export default function Profile() {
  const { user } = useLoaderData<typeof loader>()
  return <p>Signed in as {user.emails?.[0]?.value}</p>
}

If this protected loader may receive the initial callback, preserve the original Response headers when adapting it; otherwise its Set-Cookie headers are lost. A dedicated callback/root loader avoids that issue.

Sign out

Wire a route to logoutLoader, which clears the session and redirects:

// app/routes/logout.ts
import { logoutLoader } from "@authdog/remix-node"
export const loader = logoutLoader

Pair the loader-resolved session with your authorization model to decide what a user may do.

Next steps

Learn more