diff --git a/README.md b/README.md index c761ebff6..4f6247d94 100644 --- a/README.md +++ b/README.md @@ -335,7 +335,8 @@ Scope any of them with a Turborepo filter: `bun run dev --filter=api`. Because sign-in goes through an identity provider, there is no way to get a session from a terminal — `dev:session` writes the rows Better Auth would have written and prints the cookie it -would have set. It refuses to run with `NODE_ENV=production`. +would have set, along with a console snippet to log in directly on `http://localhost:3000`. +It refuses to run with `NODE_ENV=production`. ## Deploying diff --git a/apps/api/scripts/dev-session.ts b/apps/api/scripts/dev-session.ts index 8df9b3dd5..48ae305e6 100644 --- a/apps/api/scripts/dev-session.ts +++ b/apps/api/scripts/dev-session.ts @@ -62,6 +62,18 @@ await db.session.upsert({ update: { expiresAt }, }); -console.log(`${COOKIE_NAME}=${await signCookieValue(token)}`); +const cookieValue = await signCookieValue(token); +console.log(`${COOKIE_NAME}=${cookieValue}`); + +if (process.stderr.isTTY) { + const appUrl = (process.env.APP_URL ?? "http://localhost:3000") + .split(",")[0] + .trim(); + console.error(`\nTo sign in on ${appUrl}:`); + console.error("Paste this in the DevTools Console (F12) and press Enter:\n"); + console.error( + ` document.cookie = "${COOKIE_NAME}=${cookieValue}; path=/; max-age=${SESSION_DAYS * 86400}"; location.href = "/";\n`, + ); +} await db.$disconnect(); diff --git a/apps/app/app/(landing)/sign-in/page.tsx b/apps/app/app/(landing)/sign-in/page.tsx index 5b0e451af..4891539c4 100644 --- a/apps/app/app/(landing)/sign-in/page.tsx +++ b/apps/app/app/(landing)/sign-in/page.tsx @@ -95,8 +95,10 @@ async function SignIn({
Set GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET — or MICROSOFT_CLIENT_ID
- and MICROSOFT_CLIENT_SECRET — in the root .env file and restart. Your
- own identity provider can be added from Settings once somebody is
+ and MICROSOFT_CLIENT_SECRET — in the root .env file and restart. For
+ local development without OAuth, mint a session with{" "}
+ bun run --filter=api dev:session.
+ Your own identity provider can be added from Settings once somebody is
signed in.