OneTrial with Supabase Auth

  1. Snippet on the signup page:
html
<script src="https://onetrial.dev/v1.js" data-key="YOUR_PUBLIC_KEY" async></script>
  1. Send the token with the form:
js
// Signup form (browser): include the token in your POST
const token = await OneTrial.getToken(); // window.OneTrial is set by the snippet
OneTrial.markSubmit(); // records time-to-submit
formData.append('visitorToken', token);
  1. Decide in the step after auth.signUp:
ts
// Supabase Edge Function or your server, AFTER supabase.auth.signUp succeeds:
const { data: { user } } = await supabase.auth.signUp({ email, password });
const userId = user!.id;
const res = await fetch('https://onetrial.dev/api/v1/decisions', {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.ONETRIAL_API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ visitorToken, email, ip, userId }),
});
const d = await res.json();
if (d.decision === 'deny') return showPaidPlanOrSupport();
if (d.decision === 'challenge') return redirect(d.challengeUrl); // trial unlocks on the challenge.completed webhook
createTrial(userId);
// On deny: supabase.auth.admin.deleteUser(userId) or leave the account without a trial.
  1. Env: ONETRIAL_API_KEY=ot_test_... (server only). Test keys hit the same engine; switch to ot_live_ when you go live.
  2. Verify: GET /api/v1/integration/status returns a checklist. Shadow mode is on until you flip it.