Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 13 additions & 1 deletion apps/api/scripts/dev-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
6 changes: 4 additions & 2 deletions apps/app/app/(landing)/sign-in/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ async function SignIn({

<p className="text-center text-muted-foreground text-sm/5">
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{" "}
<code className="text-xs">bun run --filter=api dev:session</code>.
Your own identity provider can be added from Settings once somebody is
signed in.
</p>
</>
Expand Down
4 changes: 4 additions & 0 deletions docs/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down