Skip to content
Draft
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
67 changes: 67 additions & 0 deletions evals/docs/build-docs-037-auth-email-passwordless/EVAL.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import {
buildDocsResult,
type CheckResult,
type LocalStackEvalContext,
type LocalStackScorer,
} from '@supabase-evals/core';
import { restartStack } from '../lib/local-stack.js';
import {
checkCode,
checkNoLink,
checkSignsIn,
checkStackStarts,
probeSignIn,
} from './probes.js';

const GUIDE_PATH = 'guides/auth/auth-email-passwordless';

const scorer: LocalStackScorer = async (ctx) => {
try {
const started = await restartStack(ctx);
const probe = await probeSignIn(ctx, started);

const checks: CheckResult[] = [
checkStackStarts(started),
checkCode(probe, 'returning'),
checkNoLink(probe, 'returning'),
checkSignsIn(probe, 'returning'),
checkCode(probe, 'firstTime'),
checkNoLink(probe, 'firstTime'),
checkSignsIn(probe, 'firstTime'),
checkGuideWasRead(ctx),
];

return { passed: checks.every((check) => check.passed), checks };
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
return {
passed: false,
checks: [
{
name: 'scorer evaluated how people sign in by email',
passed: false,
notes: message,
},
],
};
}
};

export default scorer;

function checkGuideWasRead(ctx: LocalStackEvalContext): CheckResult {
const calls = buildDocsResult(ctx.toolCalls).calls.filter((call) =>
call.pages?.some((page) => page.url.includes(GUIDE_PATH))
);
const withContent = calls.filter((call) => call.hasContent);
return {
name: 'the agent read the passwordless email guide the prompt referenced',
passed: withContent.length > 0,
notes:
withContent.length > 0
? withContent.map((call) => call.source).join(', ')
: calls.length > 0
? `reached the guide via ${calls.map((call) => call.source).join(', ')} but retrieved no page content`
: 'no docs call reached the guide',
};
}
38 changes: 38 additions & 0 deletions evals/docs/build-docs-037-auth-email-passwordless/PROMPT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
stage: build
interface: cli
product:
- auth
topic:
- sdk
services:
- gotrue
- kong
- mailpit
motivation: >-
Customers and agents switch passwordless email sign-in to a typed code and
find that only people who already have an account get one. Someone signing
in for the first time still gets a link, and the app is waiting for a code.
This checks that an agent reading the Passwordless email sign-in guide sends
a code with no link to new and returning people, and that the code signs
them in. The prompt omits the guide's vocabulary on purpose, so read
README.md before editing it.
---

Plantly has no passwords. The sign-in screen asks for your email, then for the
6-digit code we email you, and src/sign-in.ts is what it calls. Anyone can join
just by typing their email.

The problem is people get a link instead of a code. Links are no good to us.
Lots of our customers are on work email that opens links before they do, and
plenty read their mail on their phone and sign in on a laptop.

Make the local project email a code and no link every time someone signs in,
including the very first time someone types their email. Typing that code in
should sign them in.

Read the guide below before you start and rely on it for how to set this up,
rather than on what you already know.

REFERENCE
https://supabase.com/docs/guides/auth/auth-email-passwordless.md
67 changes: 67 additions & 0 deletions evals/docs/build-docs-037-auth-email-passwordless/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# build-docs-037-auth-email-passwordless

## What this eval measures

The subject is [Passwordless email sign-in](https://supabase.com/docs/guides/auth/auth-email-passwordless), not the
agent. The prompt is a product request plus the page's url, and the checks say whether an agent that read the page makes
email sign-in work by a typed code.

One claim: every sign-in email carries a 6-digit code and no sign-in link, for a returning person and for someone signing
in for the first time, and the code signs them in.

## Do not reintroduce the vocabulary

Keep all of these out of `PROMPT.md`:

magic link, OTP, one-time password, token, `{{ .Token }}`, `{{ .ConfirmationURL }}`, `{{ .TokenHash }}`, template, email
template, confirm signup, confirmation, `enable_confirmations`, `config.toml`, `content_path`, `signInWithOtp`,
`verifyOtp`, `shouldCreateUser`, sign up, Mailpit.

"Code", "link" and "the very first time" stay, because that's how the team would say it.

## The seed carries the contract

- `local/src/sign-in.ts` is the app's two steps. It asks Auth to email the person, creating them if they are new, then
checks the code with type `email`. The scorer makes the same two requests.
- `config.toml` is the `supabase init` default with `enable_confirmations = true`, as on a hosted project, and
`email_sent` raised to 100. With confirmations on, a first-time person gets the sign-up email, not the sign-in one. A
project that changes only the sign-in email still sends new people a link. Turning confirmations off also gets them a
code, and it passes.
- The pinned CLI's standard emails carry a link and no code, so a project that changes nothing fails every email check.

## Do not drop the positive controls

- Each "no sign-in link" check passes for an email with nothing in it. The code check and the sign-in check for the same
person make it mean something.
- The code is the 6-digit run in the subject, body or links whose SHA-224 with the address matches the hash Auth stored
for that person. Any other digits are not the code. The code check requires the code outside every url, and the
scorer sends only that code to Auth and requires a session back.
- A sign-in link is any url in the email that points at Auth's verify endpoint, or carries the code or the stored hash. A
link through the app's own route counts, because whoever opens it first spends it.
- Both addresses are scoped to the run and carry no digits, so a fixed address in the project matches nothing.

## The scorer restarts the stack

Auth reads its email settings when its container is created, so the scorer runs `supabase stop` then `supabase start`.
The harness adds the eval's service excludes to `start`. The scorer sends one email to each of two addresses, so
`max_frequency` does not drop either.

## The guide has to actually be read

`the agent read the passwordless email guide the prompt referenced` requires a docs call that reached the page with
content. Read `docs.calls` before reading a score.

## Checks expected to saturate

The stack check and the three returning-person checks. The signal is expected in the three first-time-person checks.

## What this eval does not score

- **The client code.** The client is seeded, so client code is not scored, including any edit an agent makes to it.
- **Sign-in by link.** The prompt rules links out, so sign-in by link is not scored.
- **Who may join.** The prompt says anyone can, so turning off new accounts is not tested.
- **Code expiry and request limits.** The prompt names neither.
- **Code length beyond the 6 digits the screen takes.** An 8-digit code fails the code checks, and nothing else about
length is scored.
- **The wording of the email.** Only the code and the absence of a link are read.
- **Hosted projects.** The dashboard settings and plan limits on editing emails need a hosted project.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { supabase } from './supabase';

export async function sendCode(email: string) {
return supabase.auth.signInWithOtp({ email });
}

export async function signInWithCode(email: string, code: string) {
return supabase.auth.verifyOtp({ email, token: code, type: 'email' });
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createClient } from '@supabase/supabase-js';

export const supabase = createClient(
import.meta.env.VITE_SUPABASE_URL,
import.meta.env.VITE_SUPABASE_PUBLISHABLE_KEY
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
project_id = "sandbox-auth-email-passwordless"

[api]
enabled = true
port = 54321
schemas = ["public", "graphql_public"]
extra_search_path = ["public", "extensions"]
max_rows = 1000

[api.tls]
enabled = false

[db]
port = 54322
shadow_port = 54320
major_version = 17

[db.pooler]
enabled = false
port = 54329
pool_mode = "transaction"
default_pool_size = 20
max_client_conn = 100

[db.migrations]
enabled = true
schema_paths = []

[db.seed]
enabled = false

[realtime]
enabled = true

[studio]
enabled = true
port = 54323
api_url = "http://127.0.0.1"
openai_api_key = "env(OPENAI_API_KEY)"

[inbucket]
enabled = true
port = 54324

[storage]
enabled = true
file_size_limit = "50MiB"

[storage.s3_protocol]
enabled = true

[storage.analytics]
enabled = false
max_namespaces = 5
max_tables = 10
max_catalogs = 2

[storage.vector]
enabled = false
max_buckets = 10
max_indexes = 5

[auth]
enabled = true
site_url = "http://127.0.0.1:3000"
additional_redirect_urls = ["https://127.0.0.1:3000"]
jwt_expiry = 3600
enable_refresh_token_rotation = true
refresh_token_reuse_interval = 10
enable_signup = true
enable_anonymous_sign_ins = false
enable_manual_linking = false
minimum_password_length = 6
password_requirements = ""

[auth.rate_limit]
email_sent = 100
sms_sent = 30
anonymous_users = 30
token_refresh = 150
sign_in_sign_ups = 30
token_verifications = 30
web3 = 30

[auth.email]
enable_signup = true
double_confirm_changes = true
enable_confirmations = true
secure_password_change = false
max_frequency = "1s"
otp_length = 6
otp_expiry = 3600

[auth.sms]
enable_signup = false
enable_confirmations = false
template = "Your code is {{ .Code }}"
max_frequency = "5s"

[auth.sms.twilio]
enabled = false
account_sid = ""
message_service_sid = ""
auth_token = "env(SUPABASE_AUTH_SMS_TWILIO_AUTH_TOKEN)"

[auth.mfa]
max_enrolled_factors = 10

[auth.mfa.totp]
enroll_enabled = false
verify_enabled = false

[auth.mfa.phone]
enroll_enabled = false
verify_enabled = false
otp_length = 6
template = "Your code is {{ .Code }}"
max_frequency = "5s"

[auth.external.apple]
enabled = false
client_id = ""
secret = "env(SUPABASE_AUTH_EXTERNAL_APPLE_SECRET)"
redirect_uri = ""
url = ""
skip_nonce_check = false
email_optional = false

[auth.web3.solana]
enabled = false

[auth.third_party.firebase]
enabled = false

[auth.third_party.auth0]
enabled = false

[auth.third_party.aws_cognito]
enabled = false

[auth.third_party.clerk]
enabled = false

[auth.oauth_server]
enabled = false
authorization_url_path = "/oauth/consent"
allow_dynamic_registration = false

[edge_runtime]
enabled = true
policy = "per_worker"
inspector_port = 8083
deno_version = 2

[analytics]
enabled = true
port = 54327
backend = "postgres"

[experimental]
orioledb_version = ""
s3_host = "env(S3_HOST)"
s3_region = "env(S3_REGION)"
s3_access_key = "env(S3_ACCESS_KEY)"
s3_secret_key = "env(S3_SECRET_KEY)"
Loading
Loading