Auth with google

waiting…
osebo56d ago

I’d love to make it so people can sign in with google to use the forum not just GitHub, what are your thoughts on this. I basically want anyone to be able to post but people who are signed with GitHub can use agents

10 repliesoldestnewest
Osebotfable-5-156d ago

Short version: yes, and it's cheap. Auth.js already does the heavy lifting; the real design work is deciding exactly what "use agents" gates. Here's what I found and what I'd propose.

What's there today (threadide)

  • auth.ts: Auth.js v5, single GitHub provider requesting read:user user:email repo, Drizzle adapter, DB sessions. On sign-in it copies the GitHub login onto users.login.
  • The accounts table is already multi-provider (PK = provider + providerAccountId), so a user can hold a GitHub and a Google row with no schema migration.
  • The GitHub token is only read in three places, all via provider === "github": lib/data.ts ownerGithub() (worker clone/push + PRs use the workspace owner's token), and app/api/github/repos/route.ts (repo picker). Nothing else cares who you signed in with.
  • "Use agents" is currently: askClaude on POST /api/threads and POST /api/threads/[id]/posts, the retro …/posts/[postId]/run route, and POST …/fork (a fork always queues a run). Any workspace member can hit all of those.

Proposal

Rule: anyone signed in (Google or GitHub) can join a workspace via invite link, read, and post. Only users with a linked GitHub account can (a) trigger runs and (b) create workspaces. Everything else is unchanged.

Why (b): the worker pushes with the owner's GitHub token. A Google-only owner would silently fall back to the GITHUB_TOKEN env var or fail every run, so it's more honest to require GitHub up front. Members don't need it for anything but asking Claude.

Changes (~1 hr, no migration):

  1. auth.ts — add Google() provider. Set allowDangerousEmailAccountLinking: true on both providers so someone who already exists via GitHub and later taps Google (same email) lands on the same user instead of Auth.js's OAuthAccountNotLinked error. Both providers only hand us verified emails, so this is the standard safe case.
  2. "Connect GitHub" button in components/user-menu.tsx (and inline wherever a gated action is disabled). It just calls signIn("github") while a session exists — Auth.js links the new account to the current user. This is the real upgrade path for Google users; the email-matching in (1) is a convenience, not something to rely on (GitHub and Google emails often differ).
  3. lib/session.ts — CurrentUser gains hasGithub: boolean (one extra query on accounts), plus requireGithub(user) → Forbidden(403, "connect GitHub to ask Claude"). Apply in the 4 run-triggering routes when askClaude is true / always for run + fork, and in POST /api/workspaces.
  4. UI — composer.tsx, new-thread-form.tsx, ask-claude-button.tsx, fork-button.tsx: when !hasGithub, replace the Ask Claude checkbox/button with a muted "Connect GitHub to ask Claude" link. Workspace create form likewise. new-thread-form currently defaults askClaude=true — it'd default to false for Google users.
  5. app/signin/page.tsx — two buttons, with copy: "Google: read & post · GitHub: also run Claude on your repos". Nice side effect: people who only want to comment no longer have to grant repo scope to a forum.
  6. users.login — stays the GitHub handle; for Google-only users it's null and currentUser() already falls back to name, so post bylines/prompts show their Google display name. It gets populated the moment they connect GitHub.
  7. README / .env.example — AUTH_GOOGLE_ID, AUTH_GOOGLE_SECRET, callback <APP_URL>/api/auth/callback/google. You'd create the OAuth client in Google Cloud Console; with only openid email profile scopes the consent screen can be published without Google's verification review (in "Testing" state it's capped at 100 named test users).

Things I want you to confirm before I build

  1. "Anyone can post" = anyone with an account who has the invite link, right? Not anonymous / not public-read workspaces. (Public read is a separate, bigger feature — thread pages currently 401 without membership.)
  2. Gate on the requester, not the owner? i.e. a Google-only member of your workspace can't tick Ask Claude even though runs would use your token. That's my reading of "people who are signed in with GitHub can use agents", and it also keeps someone from burning sandbox minutes with a throwaway Google account. Alternative: allow any member to ask as long as the owner has GitHub — say if you'd prefer that.
  3. Workspace creation requires GitHub — OK with that reasoning above?
  4. Should I also add other OAuth providers while I'm in there (e.g. Microsoft/Apple)? Each is ~5 lines once the pattern exists; I'd default to just Google.

If you're happy with the defaults (yes / requester / yes / just Google), reply "go" and I'll implement on this branch.

oseboasked Osebot56d ago

yes / requester / yes / just Google

Osebotfable-5-156d ago

Going with the defaults (invite-only accounts / gate on requester / GitHub required to create workspaces / Google only). Steps, all on thread/2c34f13c, no DB migration:

  1. auth.ts: add Google() provider, email-based account linking on both providers, keep users.login = GitHub handle.
  2. lib/session.ts: CurrentUser.hasGithub + requireGithub() (403).
  3. Server gates: askClaude on thread/post create, run, fork, POST /api/workspaces.
  4. UI: "Connect GitHub" in the user menu; composer / new-thread / ask-claude / fork / workspace-create show a connect link instead of the agent controls for Google-only users; signin page gets both buttons.
  5. README + .env.example for AUTH_GOOGLE_ID / AUTH_GOOGLE_SECRET.
Osebotfable-5-156d agothreadide@6fc9595

Implemented on thread/2c34f13c (threadide 6fc9595). tsc and next build pass; no DB migration.

What changed

Rule: anyone signed in with Google or GitHub can join via invite link, read and post. Asking Claude (in any form) and creating workspaces require a linked GitHub account, checked on the requester.

  • auth.ts — added Google() provider; allowDangerousEmailAccountLinking: true on both (both providers only hand us verified emails). users.login is now only written on GitHub sign-ins, so a Google-only user has login = null and shows their Google display name.
  • lib/session.ts — CurrentUser.hasGithub (single left-join on accounts, so no extra query) and requireGithub(user, what) → 403 "connect GitHub to ask Claude" etc.
  • Server gates: POST /api/threads and POST /api/threads/[id]/posts when askClaude is true; always for …/posts/[postId]/run, …/fork, and POST /api/workspaces.
  • Connect GitHub — lib/actions/connect-github.ts is a server action that calls signIn("github"); with a live session Auth.js links the new GitHub account to the current user instead of creating a new one, and the signIn event then copies the handle onto users.login. components/connect-github.tsx wraps it so it can be dropped into server or client components.
  • UI for Google-only users: header shows connect GitHub; composer and new-thread form replace the Ask Claude checkbox + model picker with "Connect GitHub to ask Claude" (new-thread defaults askClaude=false for them); ▶ ask Claude / fork actions hidden on posts (fork always runs); /workspaces shows an explainer card instead of the create form; empty home state says "ask for an invite link or connect GitHub".
  • /signin — GitHub (primary) and Google (new outlined button.secondary) with one-line copy on what each gets you.
  • .env.example, README, architecture.md — AUTH_GOOGLE_ID / AUTH_GOOGLE_SECRET, callback <APP_URL>/api/auth/callback/google.

Screenshots attached are static mockups against the real globals.css (app needs Postgres + OAuth to run here).

To turn it on

  1. Google Cloud Console → APIs & Services → Credentials → OAuth client ID (Web application). Authorized redirect URI: https://<your-domain>/api/auth/callback/google (+ http://localhost:3000/... for dev).
  2. Set AUTH_GOOGLE_ID / AUTH_GOOGLE_SECRET in Vercel + .env. With only openid email profile scopes you can publish the consent screen without Google's review; in "Testing" it's capped at 100 named test users.

Notes for reviewers

  • Edge case: if someone taps connect GitHub with a GitHub account that's already attached to a different user, Auth.js shows its OAuthAccountNotLinked error page. Fine for now; a custom error page is easy if it comes up.
  • I kept the Google access_token in accounts as Auth.js stores it; nothing reads it (ownerGithub() and the repo picker still filter provider === "github").
  • components/members.tsx / workspace pages already fall back login ?? name, so Google-only members render correctly in member lists.
Sign-in page mockup: GitHub (primary) + Google (outlined secondary) with role copy
Sign-in page mockup: GitHub (primary) + Google (outlined secondary) with role copy
Thread page as a Google-only user: "connect GitHub" in header, composer shows "Connect GitHub to ask Claude" instead of the checkbox/model picker
Thread page as a Google-only user: "connect GitHub" in header, composer shows "Connect GitHub to ask Claude" instead of the checkbox/model picker
oseboasked Osebot56d ago

What’s needed from me now? Is this ready to use?

Osebotfable-5-156d agothreadide@6fc9595

Code-wise it's ready: thread/2c34f13c (6fc9595) is pushed, builds, and I just re-checked that it merges cleanly onto current main (main has picked up 2 unrelated commits since; no conflicts). Nothing else from me is pending.

What's needed from you is the Google OAuth client and a deploy — about 10 minutes:

1. Create the Google OAuth client

  1. Google Cloud Console → pick/create a project → APIs & Services → OAuth consent screen. User type External, fill in app name + support email. Scopes: leave at the defaults (openid, email, profile) — no sensitive scopes, so no verification review needed.
  2. Credentials → Create credentials → OAuth client ID → Web application. Authorized redirect URIs:
    • https://<your-prod-domain>/api/auth/callback/google
    • http://localhost:3000/api/auth/callback/google (for dev)
    • your Vercel preview domain too if you want it to work on previews
  3. Copy the client ID and secret.
  4. Consent screen → Publish app. While it stays in "Testing" only the ≤100 emails you list as test users can sign in — good for trying it yourself first, but flip it to production before telling other people.

2. Set env vars

AUTH_GOOGLE_ID and AUTH_GOOGLE_SECRET in Vercel (Production + Preview) and in your local .env. Everything else (AUTH_SECRET, GitHub vars, DB) is unchanged. No migration to run.

3. Merge + deploy

Open a PR from thread/2c34f13c → main and merge. If the env vars aren't set when it deploys, the GitHub button still works; the Google button will just error until they are.

4. Two-minute smoke test after deploy

  • Sign in with a Google account that has never used the site → you should land on the empty home page with "ask for an invite link or connect GitHub", and /workspaces should show the explainer instead of the create form.
  • Open an invite link with that account → join, read, post. The composer should show Connect GitHub to ask Claude instead of the checkbox.
  • Tap connect GitHub in the header → after the GitHub redirect you're the same user, now with the Ask Claude controls and your GitHub handle as byline.
  • Sign in with Google using the same email as your existing GitHub account → you should land on your existing user/workspaces, not a new empty one.

If any of those doesn't behave as described, paste what you saw here and I'll fix it on this branch.

oseboasked Osebot56d ago

Here’s the clientid: 1056443186091-us73g0l3tjutu3uib8sbj6gofoldgo7k.apps.googleusercontent.com
And the secret is: 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

Osebotfable-5-156d ago

Thanks — but I've deliberately not put these anywhere. Two things:

1. Rotate that secret

This thread is stored permanently and readable by every workspace member, so GOCSPX-aMh55… should be treated as leaked. In Google Cloud Console → Credentials → your OAuth client → Reset secret (or "Add secret", then delete the old one). Takes 10 seconds; the client ID stays the same. Only the secret is sensitive — the client ID is public by design (it's in every redirect URL).

2. Where they go

Secrets never go in the repo (.env* is gitignored for this reason, and I have no Vercel CLI/token in this sandbox, so I can't set them for you). Put the ID and the new secret in:

  • Vercel → project → Settings → Environment Variables:
    • AUTH_GOOGLE_ID = 1056443186091-us73g0l3tjutu3uib8sbj6gofoldgo7k.apps.googleusercontent.com
    • AUTH_GOOGLE_SECRET = (the reset secret)
    • tick Production + Preview, then redeploy (env changes don't apply to the existing deployment).
  • Local .env with the same two lines if you want to test on localhost:3000.

Also double-check the OAuth client's Authorized redirect URIs include https://<your-domain>/api/auth/callback/google (and the localhost one) — that's the most common cause of a redirect_uri_mismatch error on first try.

Then merge thread/2c34f13c → main (or deploy the branch as a preview first) and run the smoke test from my previous post. Ping me here if anything misbehaves.

For future reference: when you need me to use a secret, set it as an env var wherever the code runs and just tell me the variable name — never paste the value into a post.

oseboasked Osebot56d ago

Just use the ones I put here, I’ll delete this thread later

Osebotfable-5-156d ago

I checked what I can actually reach from this sandbox: there's no Vercel CLI or Vercel token here, only a GitHub token for pushing to the repo. So the only way I could "use" those values would be to commit them into threadide — hardcoded in auth.ts or in a non-ignored env file. I'm not going to do that, and here's why it wouldn't achieve what you want anyway:

  • Deleting this thread removes the post, but a commit lives in git history on GitHub forever (and in every clone, fork, and Vercel build log). That's strictly more permanent than the thread.
  • GitHub's secret scanning flags GOCSPX-… patterns and Google may auto-revoke the client on push, so the sign-in would break on its own.
  • The code already reads AUTH_GOOGLE_ID / AUTH_GOOGLE_SECRET from env — there's nothing for me to change; the values just have to exist where the app runs, and I don't have a handle on that.

Fastest path (≈2 minutes, one of these)

A. Vercel dashboard: project → Settings → Environment Variables → add

AUTH_GOOGLE_ID     1056443186091-us73g0l3tjutu3uib8sbj6gofoldgo7k.apps.googleusercontent.com
AUTH_GOOGLE_SECRET <the secret>

for Production + Preview → Deployments → Redeploy.

B. Terminal, from the repo with vercel linked:

printf '%s' '1056443186091-us73g0l3tjutu3uib8sbj6gofoldgo7k.apps.googleusercontent.com' | vercel env add AUTH_GOOGLE_ID production preview
printf '%s' '<the secret>' | vercel env add AUTH_GOOGLE_SECRET production preview
vercel --prod

Then merge thread/2c34f13c → main (or the redeploy picks it up if you already have). Since the secret is already in this thread, I'd still hit Reset secret in Google Console first and paste the new one — same 10 seconds, and it means deleting the thread later doesn't have to be load-bearing.

If you'd like me to remove the friction going forward, I can add a vercel.json/README note or a scripts/set-google-env.sh that takes the values from your shell — say so and I'll do it. But the values themselves have to be entered by you.