Skip to content
Merged
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
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Lint from repo root: `bunx biome ci .` (matches CI in `.github/workflows/ci.yml`
- `bun` is installed via npm into `~/.local/bin` (on `PATH` via `~/.bashrc`); the standalone bun.sh installer is blocked by the network egress policy.
- The repo's dated migrations assume a pre-existing hosted base schema. `supabase/migrations/00000000000000_local_base_schema.sql` reconstructs it (tables, signup trigger, slug triggers, `pgmq_public` wrappers, storage policies) so a fresh `supabase start` / `supabase db reset` works locally. It is guarded to be a no-op where objects already exist.
- App env lives in `apps/cursor/.env` (gitignored). For local dev it uses the Supabase CLI's well-known local default keys (`supabase status` prints them) with `NEXT_PUBLIC_SUPABASE_URL=http://127.0.0.1:54321`. `CRON_SECRET` guards `/api/queue/plugin-scans/drain` and `/api/cron/*`.
- The login page only offers GitHub/Google OAuth, which are not configured locally. Create a confirmed user via the GoTrue admin API (`POST {SUPABASE_URL}/auth/v1/admin/users` with the secret key, `"email_confirm": true`); a DB trigger provisions the `public.users` profile row. To get a browser session, add a temporary route that calls `supabase.auth.signInWithPassword(...)` with the server client (do not commit it). To use `/admin/plugins` and the MCP server, add the user to the `public.admins` table: `insert into public.admins (user_id) values ('<id>')`. Email rows only match Google/GitHub identities, so local password users need a `user_id` row.
- The login page only offers X, GitHub and Google sign-in, which are not configured locally. Create a confirmed user via the GoTrue admin API (`POST {SUPABASE_URL}/auth/v1/admin/users` with the secret key, `"email_confirm": true`); a DB trigger provisions the `public.users` profile row. To get a browser session, add a temporary route that calls `supabase.auth.signInWithPassword(...)` with the server client (do not commit it). To use `/admin/plugins` and the MCP server, add the user to the `public.admins` table: `insert into public.admins (user_id) values ('<id>')`. Email rows only match Google/GitHub identities, so local password users need a `user_id` row.
- The publishable key has no access to the database: `anon` and `authenticated` hold no privileges on `public` (`20261123230000_server_only_data_api.sql`), so a query made from the browser or with a member's session fails with `permission denied`. Both sites query from the server with the secret key (`utils/supabase/admin-client`) after checking the session themselves, and name the member's own row in the query; the browser and cookie clients are for signing in, reading the session and uploading pictures to storage. A new table needs no grants or policies, and there are no row-level policies to keep up: an event trigger (`keep_public_schema_closed`) turns row-level security on for a new table in `public` and takes the publishable key's access to it and to any new function away. Members can't write to storage either: `createUploadUrlAction` picks the folder and file name and returns a one-time upload address, and the bucket takes pictures only.
- Cache Components (`cacheComponents: true`) makes pages with `generateStaticParams` throw 500 on an empty database — seed at least one active plugin. Use `bun run seed:extract` / `seed:insert`, but note: the insert script must be run as `bun run --conditions=react-server --env-file=apps/cursor/.env apps/cursor/src/scripts/insert-from-jsonl.ts` or the `server-only` import throws under plain `bun run`. GitHub Code Search (used by `seed:extract` discovery) is heavily rate-limited; hand-writing `apps/cursor/.seed/candidates.json` with `{"candidates":[{"owner":...,"repo":...,"source":"seed:topic","matchedQuery":"manual"}]}` skips discovery.
- The quickest seed is the Cursor Marketplace import: `bun run seed:marketplace-plugins` from `apps/cursor` inserts ~500 official plugins from the public `ListMarketplacePlugins` catalog in about 20 seconds (no GitHub rate limits) and is safe to re-run.
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ All content is submitted through the website — no pull requests needed for dat
### Submit a Plugin

1. Go to [grok-build.directory/plugins/new](https://grok-build.directory/plugins/new)
2. Sign in with GitHub or Google
2. Sign in with X, GitHub or Google
3. Paste a GitHub repo URL — we auto-detect components following the [Open Plugins](https://open-plugins.com) standard
4. Click **Submit**

Expand Down Expand Up @@ -165,7 +165,10 @@ needs a redeploy. Fill in one of:
- `user_id`: an existing account (`auth.users.id`).
- `email`: someone who hasn't signed in yet, or any of their accounts. It only
matches a Google or GitHub sign-in whose provider verified that address; an
email typed into an email/password signup never counts.
email typed into an email/password signup never counts, and neither does
one that only X vouches for. Someone added by email who signs in with X
becomes an admin once they have also signed in with Google or GitHub on the
same account.

```sql
-- By email, works before they sign in with Google or GitHub
Expand Down
11 changes: 8 additions & 3 deletions apps/cursor/src/app/auth/callback/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
signInErrorFrom,
signInErrorFromExchange,
} from "@/lib/sign-in-errors";
import { parseSignInMethod, rememberSignIn } from "@/lib/sign-in-methods";
import { createClient } from "@/utils/supabase/server";

// `next` comes from the query string and is appended to a base URL, so values
Expand Down Expand Up @@ -34,6 +35,8 @@ export async function GET(request: Request) {
const code = searchParams.get("code");
const next = safeNextPath(searchParams.get("next"), origin);
const site = siteOrigin(request, origin);
// Which button started this sign-in (set by SignInButtons).
const via = parseSignInMethod(searchParams.get("via"));

let failure: SignInError;

Expand All @@ -42,7 +45,9 @@ export async function GET(request: Request) {
const { error } = await supabase.auth.exchangeCodeForSession(code);

if (!error) {
return NextResponse.redirect(`${site}${next}`);
const response = NextResponse.redirect(`${site}${next}`);
// The sign-in panel marks this way "Last used" from now on.
return via ? rememberSignIn(response, via) : response;
}

failure = signInErrorFromExchange(error);
Expand All @@ -64,8 +69,8 @@ export async function GET(request: Request) {
});
}

// Back to the sign-in page, which says what happened and offers both
// methods again. It keeps the page the visitor was heading for.
// Back to the sign-in page, which says what happened and offers every way
// in again. It keeps the page the visitor was heading for.
const login = new URL("/login", site);
login.searchParams.set("error", failure);
if (next !== "/") login.searchParams.set("next", next);
Expand Down
32 changes: 0 additions & 32 deletions apps/cursor/src/components/github-signin.tsx

This file was deleted.

32 changes: 0 additions & 32 deletions apps/cursor/src/components/google-signin.tsx

This file was deleted.

16 changes: 16 additions & 0 deletions apps/cursor/src/components/icons/x-icon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { SVGProps } from "react";

export function XIcon({ className, ...props }: SVGProps<SVGSVGElement>) {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="currentColor"
aria-hidden="true"
className={className}
{...props}
>
<path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z" />
</svg>
);
}
14 changes: 9 additions & 5 deletions apps/cursor/src/components/login.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use client";

import { GithubSignin } from "./github-signin";
import { GoogleSignin } from "./google-signin";
import { SignInButtons } from "./sign-in-buttons";

export function Login({ redirectTo }: { redirectTo?: string }) {
return (
Expand All @@ -12,10 +11,15 @@ export function Login({ redirectTo }: { redirectTo?: string }) {
thousands of developers building with Grok Build.
</p>

<div className="mt-8 flex flex-col gap-3">
<GithubSignin redirectTo={redirectTo} />
<GoogleSignin redirectTo={redirectTo} />
<div className="mt-8">
<SignInButtons redirectTo={redirectTo} />
</div>

{/* A different way in can be a different, empty account: see
lib/sign-in-methods.ts. */}
<p className="mt-4 text-xs text-muted-foreground">
Already a member? Sign in the way you did before.
</p>
</div>
);
}
97 changes: 97 additions & 0 deletions apps/cursor/src/components/sign-in-buttons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
"use client";

import { useSearchParams } from "next/navigation";
import { useEffect, useState } from "react";
import { GithubIcon } from "@/components/icons/github-icon";
import { GoogleIcon } from "@/components/icons/google-icon";
import { XIcon } from "@/components/icons/x-icon";
import {
readLastSignIn,
SIGN_IN_METHOD_NAME,
SIGN_IN_METHODS,
type SignInMethod,
} from "@/lib/sign-in-methods";
import { createClient } from "@/utils/supabase/client";
import { Button } from "./ui/button";

const ICONS: Record<SignInMethod, typeof XIcon> = {
x: XIcon,
github: GithubIcon,
google: GoogleIcon,
};

/**
* One button for each way to sign in, the preferred one first and filled.
* They go through the same sign-in service as the Grok Bot Directory
* (apps/grok-bot sign-in-buttons.tsx), so a member is the same member on
* both sites.
*/
export function SignInButtons({ redirectTo }: { redirectTo?: string }) {
const searchParams = useSearchParams();
const next = searchParams.get("next") ?? redirectTo ?? "/";
const [pending, setPending] = useState<SignInMethod | null>(null);
const [unavailable, setUnavailable] = useState(false);
// Known only in the browser, so it is read once the panel is showing.
const [lastUsed, setLastUsed] = useState<SignInMethod | null>(null);

useEffect(() => {
setLastUsed(readLastSignIn());

// The Back button can bring this page back exactly as it was left, with
// a button still saying "Signing in…" and all of them switched off.
const restore = (event: PageTransitionEvent) => {
if (event.persisted) setPending(null);
};
window.addEventListener("pageshow", restore);
return () => window.removeEventListener("pageshow", restore);
}, []);

async function signIn(method: SignInMethod) {
setPending(method);
setUnavailable(false);
// `via` tells the callback which button started this sign-in.
const callback = new URLSearchParams({ next, via: method });
const { error } = await createClient().auth.signInWithOAuth({
provider: method,
options: {
redirectTo: `${window.location.origin}/auth/callback?${callback}`,
},
});
if (error) {
setUnavailable(true);
setPending(null);
}
}

return (
<div className="flex flex-col gap-3">
{SIGN_IN_METHODS.map((method, index) => {
const Icon = ICONS[method];
return (
<Button
key={method}
variant={index === 0 ? "default" : "outline"}
className="gap-2"
disabled={pending !== null}
onClick={() => signIn(method)}
>
<Icon className="size-4" />
{pending === method
? "Signing in…"
: `Sign in with ${SIGN_IN_METHOD_NAME[method]}`}
{lastUsed === method && (
<span className="rounded-full bg-current/15 px-2 py-0.5 text-[11px] leading-tight">
Last used
</span>
)}
</Button>
);
})}
{unavailable && (
<p role="alert" className="text-sm text-muted-foreground">
Sign-in isn’t available right now. Try again in a moment.
</p>
)}
</div>
);
}
4 changes: 2 additions & 2 deletions apps/cursor/src/lib/sign-in-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ export const SIGN_IN_ERROR_MESSAGES: Record<
unverified_email: {
title: "That email address isn't verified",
detail:
"Verify the email address on your GitHub or Google account, then sign in again.",
"Verify the email address on the account you sign in with, then sign in again.",
},
failed: {
title: "Sign-in didn't work",
detail: "Please try again, or use the other sign-in method.",
detail: "Please try again, or sign in another way.",
},
};

Expand Down
50 changes: 50 additions & 0 deletions apps/cursor/src/lib/sign-in-methods.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import type { NextResponse } from "next/server";

/**
* The ways to sign in, in the order the sign-in panel shows them. The first
* is the preferred one and gets the filled button.
*/
export const SIGN_IN_METHODS = ["x", "github", "google"] as const;
export type SignInMethod = (typeof SIGN_IN_METHODS)[number];

export const SIGN_IN_METHOD_NAME: Record<SignInMethod, string> = {
x: "X",
github: "GitHub",
google: "Google",
};

// Remembers how this browser last signed in, so the sign-in panel can mark
// that button "Last used". Two ways in lead to the same account only when
// both vouch for the same email address. Otherwise a member who comes back
// another way lands in a new, empty account, so it helps to show which way
// was theirs.
const COOKIE = "last_sign_in";

export function parseSignInMethod(
value: string | null | undefined,
): SignInMethod | null {
return SIGN_IN_METHODS.find((method) => method === value) ?? null;
}

/** On the server, once a sign-in has completed: remember how it was done. */
export function rememberSignIn(response: NextResponse, method: SignInMethod) {
response.cookies.set(COOKIE, method, {
path: "/",
maxAge: 60 * 60 * 24 * 400,
sameSite: "lax",
secure: process.env.NODE_ENV === "production",
// Read in the browser: the sign-in panel is also shown in dialogs and on
// pages the server renders once for everyone.
httpOnly: false,
});
return response;
}

/** In the browser: how this browser last signed in, if it has. */
export function readLastSignIn(): SignInMethod | null {
if (typeof document === "undefined") return null;
const entry = document.cookie
.split("; ")
.find((cookie) => cookie.startsWith(`${COOKIE}=`));
return parseSignInMethod(entry?.slice(COOKIE.length + 1));
}
3 changes: 2 additions & 1 deletion apps/grok-bot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ a real shared bot from x.ai.
`https://service.cursor.directory/auth/v1/callback`. A project owner turns
on Authentication → Sign In / Providers → X / Twitter (OAuth 2.0) with its
client id and secret; then set `GROK_BOT_X_SIGN_IN=1` on Vercel to show the
button. cursor.directory is unaffected (it has no X button).
button here. grok-build.directory always shows its X button (it has no
switch), so the provider has to stay on.
- **Vercel:** a new project with root directory `apps/grok-bot`, the domain,
the env vars in `.env.example`, and the Firewall rules listed there.
- **Database:** apply the four migrations (`20261030120000_grok_bots.sql`,
Expand Down
9 changes: 4 additions & 5 deletions apps/grok-bot/src/components/sign-in-buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ function LastUsed() {
}

/**
* Same GitHub and Google sign-in as cursor.directory (apps/cursor
* github-signin.tsx and google-signin.tsx) through the shared Supabase
* project, so accounts are the same members on both sites. X (`xSignIn`) is
* extra and stays off until X is enabled on that project
* (GROK_BOT_X_SIGN_IN=1).
* The same ways to sign in as grok-build.directory (apps/cursor
* sign-in-buttons.tsx) through the shared Supabase project, so accounts are
* the same members on both sites. Here X (`xSignIn`) stays off until
* GROK_BOT_X_SIGN_IN=1.
*/
export function SignInButtons({
next,
Expand Down
2 changes: 1 addition & 1 deletion supabase/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ skip_nonce_check = false
# If enabled, it will allow the user to successfully authenticate when the provider does not return an email address.
email_optional = false

# Sign in with X (OAuth 2.0) for Grok Bot Directory (apps/grok-bot). Put the X app's
# Sign in with X (OAuth 2.0), the first sign-in button on both sites. Put the X app's
# OAuth 2.0 client id and secret in supabase/.env (without them, set enabled = false).
[auth.external.x]
enabled = true
Expand Down
Loading