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.

diff --git a/docs/setup.md b/docs/setup.md index 03b8912f7..678582286 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -24,6 +24,10 @@ run needs `db:migrate` only for the seed that follows it. When the database and they do not match — reconcile with `db:migrate`, or `db:reset` when the divergence is an edited migration that has already been applied. +When developing without Google or Microsoft OAuth configured, mint a local session +with `bun run --filter=api dev:session` and paste the printed snippet into the +browser DevTools Console on `http://localhost:3000` to sign in. + ## Google Cloud - **Enable the Gmail API and the Google Calendar API** on the project.