Authentication
Dashild does not ship an auth library. The panel needs two things from the app:
export const panel = definePanel({ // ... auth: { getCurrentUser, signOut, // optional },});getCurrentUser runs on the server and returns the signed-in user or null.
signOut is optional; when present, the user menu shows a sign-out action.
Better Auth
Section titled “Better Auth”pnpm dashild init --auth better-auth --yesinit creates the generated auth files and connects the app to Better Auth.
--auth better-auth selects that integration; --yes applies the plan without
asking for confirmation. Review the generated files and environment variables
before using the app.
This writes:
src/lib/auth.tssrc/lib/auth-client.tssrc/lib/session.tssrc/lib/auth-actions.tssrc/lib/email.tssrc/app/api/auth/[...all]/route.tssrc/app/login/page.tsxsrc/app/signup/page.tsxsrc/app/forgot-password/page.tsxsrc/app/reset-password/page.tsxsrc/components/dashild/login-form.tsxsrc/components/dashild/signup-form.tsxsrc/components/dashild/forgot-password-form.tsxsrc/components/dashild/reset-password-form.tsxThe folders are conditional: if the app already has lib/ and components/ at
the root instead of under src/, the files go there. The app directory
follows the same rule.
It also adds better-auth to package.json.
Prisma models
Section titled “Prisma models”If the schema has none of User, Session, Account, or Verification,
init appends all four. If it finds any of them, it adds none and warns;
adapt the existing models yourself. The check is all-or-nothing.
Environment
Section titled “Environment”create-dashild writes .env and a committed .env.example. dashild init
only appends missing keys to .env.example; it never writes .env.
| Variable | Where | Purpose |
|---|---|---|
DATABASE_URL |
.env and .env.example |
App and Prisma connection. |
DIRECT_URL |
.env when given; commented placeholder in .env.example |
Non-pooled URL for migrations. |
BETTER_AUTH_SECRET |
With Better Auth | Session signing. Generate with openssl rand -base64 32. |
BETTER_AUTH_URL |
With Better Auth | Public origin; must match the browser URL. |
ALLOW_SIGNUP |
With Better Auth | false closes public sign-up. |
REQUIRE_EMAIL_VERIFICATION |
With Better Auth | true requires the verification link. |
RESEND_API_KEY |
.env.example only, commented (Better Auth) |
If set, sendEmail sends through Resend. |
EMAIL_FROM |
.env.example only, commented (Better Auth) |
Resend sender. |
The email keys are never written to .env: uncomment them there (or add them
to your deployment environment) when you configure a provider.
BETTER_AUTH_URL must match the origin you open in the browser. A mismatch
makes sign-in fail with an origin error.
Sign-up, verification, and reset
Section titled “Sign-up, verification, and reset”ALLOW_SIGNUP=falsedisables the sign-up API and the signup page shows “Sign-up disabled”. Create users from your own admin flow.REQUIRE_EMAIL_VERIFICATION=truesends the verification link on sign-up and blocks sign-in until the email is verified./forgot-passwordrequests a reset link;/reset-password?token=...sets the new password.- Rate limiting is enabled (100 requests per minute) in the generated config.
src/lib/email.ts uses Resend when RESEND_API_KEY is present:
await fetch("https://api.resend.com/emails", { method: "POST", headers: { Authorization: `Bearer ${process.env.RESEND_API_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify({ from: process.env.EMAIL_FROM ?? "Dashild <onboarding@resend.dev>", to, subject, text, }),});Without a key it logs the email in development and throws in production, so password reset and verification never lose emails silently. Replace it with Postmark, SES, or your own transport if you prefer.
Your own auth
Section titled “Your own auth”Use the default mode and fill the adapter:
pnpm dashild init --auth none --yesHere --auth none tells Dashild not to generate Better Auth. It still creates
the panel integration; you then connect your existing authentication system by
implementing getCurrentUser.
async function getCurrentUser(): Promise<CurrentUser | null> { const session = await myAuth.getSession(); if (!session) return null;
return { id: session.user.id, email: session.user.email, name: session.user.name, organizationId: session.user.organizationId, roles: session.user.roles, };}CurrentUser requires id; email, name, organizationId, and roles are
optional. Returning organizationId and roles is enough for
policies. For tenant isolation end to end, see
Multi-tenancy.
If the schema already has any Better Auth model, init --auth better-auth does
not modify the schema; it warns and leaves the adaptation to you.