All jobs

Add Magic Link Sign-In to a Supabase App

Yes. An agent reads your Supabase auth config and sign-in code, adds a passwordless email link that lands on your existing callback, and checks build and lint pass.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads how sign-in works today before adding a second way in. In a project like Razikus/supabase-nextjs-template the Next.js app under nextjs/ wraps Supabase in src/lib/supabase/unified.ts, a SassClient class whose loginEmail calls signInWithPassword, registerEmail calls signUp, and exchangeCodeForSession wraps the client call of the same name. src/app/auth/login/page.tsx collects email and password, calls loginEmail, then checks auth.mfa.getAuthenticatorAssuranceLevel() and sends the user to /auth/2fa when nextLevel is aal2, otherwise to /app. src/components/SSOButtons.tsx calls signInWithOAuth with redirectTo set to /api/auth/callback.

It reads that callback and the local config next. src/app/api/auth/callback/route.ts takes code from the query, calls exchangeCodeForSession, repeats the MFA check and redirects to /app, /auth/2fa or back to /auth/login, so a magic link that lands there needs no new route. src/lib/supabase/middleware.ts refreshes the session with createServerClient from @supabase/ssr and redirects unauthenticated requests under /app. supabase/config.toml has [auth.email] with enable_signup = true, enable_confirmations = true, max_frequency = "1m0s", otp_length = 6 and otp_expiry = 3600, and additional_redirect_urls already lists the localhost origins.

The agent adds a loginWithMagicLink(email) method to SassClient that calls signInWithOtp with emailRedirectTo set to ${window.location.origin}/api/auth/callback and shouldCreateUser taken from enable_signup, matching how SSOButtons builds its redirect. On the login page it adds a Use a magic link instead toggle that hides the password field, submits the email, and shows a Check your email state with the max_frequency cooldown reflected in a disabled resend button. It leaves loginEmail and the MFA branch alone, because the callback already runs the same check after the code exchange. In supabase/config.toml it adds a comment on the [auth.email] keys the feature depends on, and it adds a supabase/templates/magic_link.html only when the prompt asks for a custom email, pointing [auth.email.template.magic_link] at it.

Before pushing, it runs yarn build and yarn lint in nextjs/ with the .env.template values, then installs Docker, which the sandbox starts without (sudo apt-get install -y docker.io, then dockerd), and runs supabase start so it can request a link from the login page and open it from the Inbucket mail UI, following it to /api/auth/callback and on to /app. It opens the pull request with a note on what the hosted project needs: the site URL and the production origin in the redirect allow list, and a production SMTP sender since the default sender is rate limited.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Add magic link sign-in to this Supabase app. Read the Supabase client wrapper, the login page, the OAuth buttons, the auth callback route, the middleware and supabase/config.toml first. Add a method that calls signInWithOtp with emailRedirectTo pointing at the existing callback route, and a toggle on the login page that switches from password to magic link, submits the email, and shows a check-your-email state with a resend cooldown matching auth.email.max_frequency. Do not change the password login or the MFA handling. Run the build and lint before you push, install Docker (sudo apt-get install -y docker.io, start dockerd), run supabase start, request a link locally and follow it through the callback. Open a pull request that lists what the hosted project needs: redirect URLs, site URL and SMTP.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request on a new branch that changes src/lib/supabase/unified.ts to add loginWithMagicLink, src/app/auth/login/page.tsx to add the toggle and the check-your-email state, and supabase/config.toml to annotate the [auth.email] settings the feature relies on. When a custom email was requested, a supabase/templates/magic_link.html and the template setting are added too. In an app shaped like the Supabase Next.js template no new route is added, because /api/auth/callback already exchanges the code and runs the MFA check.

The proof is the next build and next lint output in the session's trajectory and the sequence of commands and page loads that requested a link, opened it from the local mail UI and arrived at /app. Any workflow the repository runs on pull requests runs here too. The pull request description lists the hosted settings a reviewer has to confirm before the link works in production: the production origin in additional_redirect_urls, the site URL, and an SMTP provider.

Before merging, a reviewer checks whether shouldCreateUser should be true for their app, that the cooldown copy matches max_frequency, that the toggle fits the login page's design, and that a user who signs in by link and has MFA enrolled still reaches /auth/2fa, which the unchanged callback guarantees.

Run it on every Linear issue labelled auth

Add an automation in the Project with a linear trigger on issues labelled auth and a prompt written like this one in general terms: read the Supabase wrapper, the auth pages, the callback and config.toml, implement what the issue asks without changing existing sign-in paths, run the build and lint, and open a pull request listing hosted settings. The trigger adds the issue after the prompt, so the agent reads the requested flow from the issue itself; nothing in input is substituted.

Each labelled issue starts one run in its own sandbox with its own pull request, and the link lands back on the issue. The automation has its own max_runs_per_hour cap. To start a single run by hand, send this request from a script with a fresh UUID as request_id so a retry returns the run already started.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

A magic link touches the client wrapper, the login page, the redirect allow list and the email settings, and the only honest test is to request a link and follow it. On Rush the agent does that in its own sandbox: it installs Docker, starts the local Supabase stack, requests a link from the page it changed, opens it from the local mail UI and follows the redirect through the existing callback, then runs the build and lint before the first push. Your machine runs nothing.

The result is checkable rather than claimed. The trajectory keeps every command and page load, the pull request names exactly which hosted settings still need a person, and the password and MFA paths are untouched by construction because the callback is shared. Because each run is independent, the same request can add the flow to several apps on the same template at once, one pull request each.

Frequently asked questions

Will it change password login or the MFA step?

No. loginEmail and the getAuthenticatorAssuranceLevel check on the login page stay as they are, and the magic link lands on /api/auth/callback, which already runs the same MFA check after exchanging the code. A user with MFA enrolled who signs in by link is sent to /auth/2fa exactly as an OAuth user is today.

Do I need a new callback route?

Not in an app shaped like this template. signInWithOtp with emailRedirectTo sends the user back with a code, and src/app/api/auth/callback/route.ts already calls exchangeCodeForSession and redirects. The agent reuses it, which is also what SSOButtons does for OAuth. If your app has no such route, the agent adds one and says so.

What has to change in the hosted Supabase project?

The production origin must be in the redirect allow list and the site URL set, and a production SMTP sender should be configured because the default sender is rate limited and meant for development. The pull request lists these, since they live in the hosted dashboard rather than in the repository. supabase/config.toml covers the local stack only.

Can a magic link create a new account?

Only if shouldCreateUser is true, which the agent sets from enable_signup in config.toml and names in the pull request so a reviewer can decide. With it false, a link requested for an unknown email signs nobody up, which is the safer default for an invite-only app.

How does it test the link without a real mailbox?

With the local Supabase stack, whose mail UI captures every email the auth service sends. A Rush sandbox starts without Docker, so the agent installs it with sudo apt-get install -y docker.io and starts dockerd, then starts the stack, requests a link from the login page, opens it from that UI and follows it to /app, and the trajectory keeps that sequence.

More Supabase jobs

More jobs like this: Hand off a long task

Keep reading