Skip to content

Embedding in your app

The screens are not hosted by ownauth. You install them into your app from its registry, like any other shadcn component, and they talk to your instance over the API.

Before any client bundle runs:

<script>window.__OWNAUTH_URL__ = "https://auth.example.com";</script>

Resolution order inside the components:

  1. createOwnAuthClient(url) — explicit
  2. globalThis.__OWNAUTH_URL__ — set by your page, as above
  3. import.meta.env.VITE_OWNAUTH_URL — Vite, Astro, Nuxt, SvelteKit
  4. the current origin — correct only when ownauth serves its own preview UI
Terminal window
npx shadcn@latest add https://auth.example.com/r/sign-in.json
npx shadcn@latest add https://auth.example.com/r/sign-up.json
npx shadcn@latest add https://auth.example.com/r/user-profile.json

Each item is source code: it lands in components/auth/ and is yours to edit. No SDK version to track, no component you cannot change.

The registry is also mirrored at https://ownauth.tariqjandaly.com/r/<name>.json if you want to try an install before running your own instance.

docker/.env
TRUSTED_ORIGINS=https://app.example.com

Exact match. CORS reflects only listed origins, with credentials allowed on those and no CORS headers at all on others.

Never trust a client-side session context for authorization. Ask ownauth:

app/protected/page.tsx
const cookieHeader = (await cookies()).getAll()
.map((c) => `${c.name}=${c.value}`).join("; ");
const response = await fetch(`${process.env.OWNAUTH_URL}/api/auth/get-session`, {
headers: { cookie: cookieHeader },
cache: "no-store",
});
const user = (await response.json())?.user ?? null;
if (!user) redirect("/");

That has a useful property: a ban, a revoked session, or a deleted account takes effect on the next request, because the answer is never cached.

Section titled “The cookie rule that decides your domain layout”

Install ownauth on a subdomain of the same registrable domain as your app:

Layout Cookie Works?
app.example.com ↔ auth.example.com first-party, shared via domain=.example.com yes
example.com/app ↔ auth.example.com first-party yes
app.example.com ↔ auth.other-domain.com third-party no — browsers block it

No configuration fixes the third row. The instance’s own console states this: Security shows which origins share the cookie and which cannot.

examples/next-app in the repository is a complete customer app: a registry-installed sign-in form and a /protected page that verifies the session server-side.