OneTrial with Auth0
- Snippet on the signup page:
html<script src="https://onetrial.dev/v1.js" data-key="YOUR_PUBLIC_KEY" async></script>
- Send the token with the form:
js// Signup form (browser): include the token in your POSTconst token = await OneTrial.getToken(); // window.OneTrial is set by the snippetOneTrial.markSubmit(); // records time-to-submitformData.append('visitorToken', token);
- Decide in a Post-Registration Action or your app backend:
ts// Auth0 Post-Registration Action or your backend after the callbackconst userId = event.user.user_id; const email = event.user.email;const visitorToken = event.request.query?.visitorToken; // forward it via loginWithRedirect({ authorizationParams: { visitorToken } })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 webhookcreateTrial(userId);
- Env:
ONETRIAL_API_KEY=ot_test_...(server only). Test keys hit the same engine; switch toot_live_when you go live. - Verify:
GET /api/v1/integration/statusreturns a checklist. Shadow mode is on until you flip it.