briven-engine-signup-smoke.mjs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * Local-only: init supertokens-node against briven-engine and sign up one user.
  3. * No production deploy. Proves engine + SDK path.
  4. *
  5. * BRIVEN_ENGINE_CONNECTION_URI=http://127.0.0.1:3567 bun scripts/briven-engine-signup-smoke.mjs
  6. */
  7. import SuperTokens from 'supertokens-node';
  8. import EmailPassword from 'supertokens-node/recipe/emailpassword';
  9. import Session from 'supertokens-node/recipe/session';
  10. import Multitenancy from 'supertokens-node/recipe/multitenancy';
  11. const connectionURI = (
  12. process.env.BRIVEN_ENGINE_CONNECTION_URI || 'http://127.0.0.1:3567'
  13. ).replace(/\/$/, '');
  14. const email = `e2e_${Date.now()}@example.com`;
  15. const password = 'E2eTest!Pass99';
  16. const tenantId = 'proj_p_e2e_local';
  17. console.log('engine', connectionURI);
  18. console.log('tenant', tenantId);
  19. console.log('email', email);
  20. // Probe Core first
  21. const hello = await fetch(`${connectionURI}/hello`);
  22. const helloText = await hello.text();
  23. if (!hello.ok || !/hello/i.test(helloText)) {
  24. console.error('FAIL core hello', hello.status, helloText);
  25. process.exit(1);
  26. }
  27. console.log('✔ core hello', helloText.trim());
  28. SuperTokens.init({
  29. supertokens: { connectionURI },
  30. appInfo: {
  31. appName: 'Briven Auth e2e',
  32. apiDomain: 'http://localhost:3001',
  33. websiteDomain: 'http://localhost:3000',
  34. apiBasePath: '/v1/auth-core/fdi',
  35. websiteBasePath: '/auth',
  36. },
  37. recipeList: [
  38. Session.init(),
  39. EmailPassword.init(),
  40. Multitenancy.init(),
  41. ],
  42. });
  43. // Ensure tenant
  44. try {
  45. const t = await Multitenancy.createOrUpdateTenant(tenantId, {
  46. emailPasswordEnabled: true,
  47. });
  48. console.log('✔ tenant', t.status, 'createdNew=', t.createdNew);
  49. } catch (err) {
  50. console.warn('tenant ensure', err instanceof Error ? err.message : err);
  51. }
  52. const signup = await EmailPassword.signUp(tenantId, email, password);
  53. console.log('signup status', signup.status);
  54. if (signup.status !== 'OK') {
  55. console.error('FAIL signup', signup);
  56. process.exit(1);
  57. }
  58. console.log('✔ userId', signup.user.id);
  59. console.log('✔ briven-engine local sign-up proof OK');
  60. process.exit(0);