@vaultix.ai/react 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -236,6 +236,7 @@ function VaultixProvider({
236
236
  "data-vaultix-after-sign-in": afterSignInUrl ?? "",
237
237
  "data-vaultix-after-sign-up": afterSignUpUrl ?? "",
238
238
  "data-vaultix-api": apiOrigin,
239
+ "data-vaultix-pk": publishableKey,
239
240
  style: { display: "contents" },
240
241
  children
241
242
  }
@@ -295,6 +296,13 @@ function resolveApiOrigin2(prop) {
295
296
  }
296
297
  return "";
297
298
  }
299
+ function resolvePk() {
300
+ if (typeof document !== "undefined") {
301
+ const el = document.querySelector("[data-vaultix-pk]");
302
+ if (el) return el.getAttribute("data-vaultix-pk") ?? "";
303
+ }
304
+ return "";
305
+ }
298
306
  function resolveAfterSignInUrl(redirectUrlProp) {
299
307
  if (redirectUrlProp) return redirectUrlProp;
300
308
  if (typeof document !== "undefined") {
@@ -338,15 +346,17 @@ function SignIn({
338
346
  }
339
347
  function handleGoogleSignIn() {
340
348
  const target = resolveAfterSignInUrl(redirectUrl);
349
+ const pk = resolvePk();
341
350
  const params = new URLSearchParams({ redirect_url: target });
342
- window.location.href = `${apiOrigin}/v1/auth/oauth/google?${params}`;
351
+ if (pk) params.set("pk", pk);
352
+ window.location.href = `${apiOrigin}/api/v1/auth/oauth/google?${params}`;
343
353
  }
344
354
  async function handleEmailSubmit(e) {
345
355
  e.preventDefault();
346
356
  setError(null);
347
357
  setLoading(true);
348
358
  try {
349
- const res = await fetch(`${apiOrigin}/v1/auth/lookup`, {
359
+ const res = await fetch(`${apiOrigin}/api/v1/auth/lookup`, {
350
360
  method: "POST",
351
361
  credentials: "include",
352
362
  headers: { "Content-Type": "application/json" },
@@ -369,10 +379,14 @@ function SignIn({
369
379
  setError(null);
370
380
  setLoading(true);
371
381
  try {
372
- const res = await fetch(`${apiOrigin}/v1/auth/sign-in`, {
382
+ const pk = resolvePk();
383
+ const res = await fetch(`${apiOrigin}/api/v1/auth/sign-in`, {
373
384
  method: "POST",
374
385
  credentials: "include",
375
- headers: { "Content-Type": "application/json" },
386
+ headers: {
387
+ "Content-Type": "application/json",
388
+ ...pk ? { "x-vaultix-pk": pk } : {}
389
+ },
376
390
  body: JSON.stringify({ email, password })
377
391
  });
378
392
  const data = await res.json();
@@ -397,7 +411,7 @@ function SignIn({
397
411
  setLoading(true);
398
412
  try {
399
413
  const optRes = await fetch(
400
- `${apiOrigin}/v1/auth/passkey/authenticate/options`,
414
+ `${apiOrigin}/api/v1/auth/passkey/authenticate/options`,
401
415
  {
402
416
  method: "POST",
403
417
  credentials: "include",
@@ -414,7 +428,7 @@ function SignIn({
414
428
  publicKey: options
415
429
  });
416
430
  const verifyRes = await fetch(
417
- `${apiOrigin}/v1/auth/passkey/authenticate/verify`,
431
+ `${apiOrigin}/api/v1/auth/passkey/authenticate/verify`,
418
432
  {
419
433
  method: "POST",
420
434
  credentials: "include",
@@ -457,7 +471,7 @@ function SignIn({
457
471
  setError(null);
458
472
  setLoading(true);
459
473
  try {
460
- const res = await fetch(`${apiOrigin}/v1/auth/totp/verify`, {
474
+ const res = await fetch(`${apiOrigin}/api/v1/auth/totp/verify`, {
461
475
  method: "POST",
462
476
  credentials: "include",
463
477
  headers: { "Content-Type": "application/json" },
@@ -480,7 +494,7 @@ function SignIn({
480
494
  setError(null);
481
495
  setLoading(true);
482
496
  try {
483
- await fetch(`${apiOrigin}/v1/auth/forgot-password`, {
497
+ await fetch(`${apiOrigin}/api/v1/auth/forgot-password`, {
484
498
  method: "POST",
485
499
  credentials: "include",
486
500
  headers: { "Content-Type": "application/json" },
@@ -505,7 +519,7 @@ function SignIn({
505
519
  setError(null);
506
520
  setLoading(true);
507
521
  try {
508
- const res = await fetch(`${apiOrigin}/v1/auth/reset-password`, {
522
+ const res = await fetch(`${apiOrigin}/api/v1/auth/reset-password`, {
509
523
  method: "POST",
510
524
  credentials: "include",
511
525
  headers: { "Content-Type": "application/json" },
@@ -861,14 +875,14 @@ function SignUp({
861
875
  function handleGoogleSignUp() {
862
876
  const target = resolveAfterSignUpUrl(redirectUrl);
863
877
  const params = new URLSearchParams({ redirect_url: target });
864
- window.location.href = `${apiOrigin}/v1/auth/oauth/google?${params}`;
878
+ window.location.href = `${apiOrigin}/api/v1/auth/oauth/google?${params}`;
865
879
  }
866
880
  async function handleEmailPassword(e) {
867
881
  e.preventDefault();
868
882
  setError(null);
869
883
  setLoading(true);
870
884
  try {
871
- const res = await fetch(`${apiOrigin}/v1/auth/sign-up`, {
885
+ const res = await fetch(`${apiOrigin}/api/v1/auth/sign-up`, {
872
886
  method: "POST",
873
887
  credentials: "include",
874
888
  headers: { "Content-Type": "application/json" },
@@ -892,7 +906,7 @@ function SignUp({
892
906
  setError(null);
893
907
  setLoading(true);
894
908
  try {
895
- const res = await fetch(`${apiOrigin}/v1/auth/email/verify`, {
909
+ const res = await fetch(`${apiOrigin}/api/v1/auth/email/verify`, {
896
910
  method: "POST",
897
911
  credentials: "include",
898
912
  headers: { "Content-Type": "application/json" },
@@ -916,7 +930,7 @@ function SignUp({
916
930
  async function resendCode() {
917
931
  if (!registrationId) return;
918
932
  try {
919
- await fetch(`${apiOrigin}/v1/auth/email/resend`, {
933
+ await fetch(`${apiOrigin}/api/v1/auth/email/resend`, {
920
934
  method: "POST",
921
935
  credentials: "include",
922
936
  headers: { "Content-Type": "application/json" },
package/dist/index.mjs CHANGED
@@ -204,6 +204,7 @@ function VaultixProvider({
204
204
  "data-vaultix-after-sign-in": afterSignInUrl ?? "",
205
205
  "data-vaultix-after-sign-up": afterSignUpUrl ?? "",
206
206
  "data-vaultix-api": apiOrigin,
207
+ "data-vaultix-pk": publishableKey,
207
208
  style: { display: "contents" },
208
209
  children
209
210
  }
@@ -263,6 +264,13 @@ function resolveApiOrigin2(prop) {
263
264
  }
264
265
  return "";
265
266
  }
267
+ function resolvePk() {
268
+ if (typeof document !== "undefined") {
269
+ const el = document.querySelector("[data-vaultix-pk]");
270
+ if (el) return el.getAttribute("data-vaultix-pk") ?? "";
271
+ }
272
+ return "";
273
+ }
266
274
  function resolveAfterSignInUrl(redirectUrlProp) {
267
275
  if (redirectUrlProp) return redirectUrlProp;
268
276
  if (typeof document !== "undefined") {
@@ -306,15 +314,17 @@ function SignIn({
306
314
  }
307
315
  function handleGoogleSignIn() {
308
316
  const target = resolveAfterSignInUrl(redirectUrl);
317
+ const pk = resolvePk();
309
318
  const params = new URLSearchParams({ redirect_url: target });
310
- window.location.href = `${apiOrigin}/v1/auth/oauth/google?${params}`;
319
+ if (pk) params.set("pk", pk);
320
+ window.location.href = `${apiOrigin}/api/v1/auth/oauth/google?${params}`;
311
321
  }
312
322
  async function handleEmailSubmit(e) {
313
323
  e.preventDefault();
314
324
  setError(null);
315
325
  setLoading(true);
316
326
  try {
317
- const res = await fetch(`${apiOrigin}/v1/auth/lookup`, {
327
+ const res = await fetch(`${apiOrigin}/api/v1/auth/lookup`, {
318
328
  method: "POST",
319
329
  credentials: "include",
320
330
  headers: { "Content-Type": "application/json" },
@@ -337,10 +347,14 @@ function SignIn({
337
347
  setError(null);
338
348
  setLoading(true);
339
349
  try {
340
- const res = await fetch(`${apiOrigin}/v1/auth/sign-in`, {
350
+ const pk = resolvePk();
351
+ const res = await fetch(`${apiOrigin}/api/v1/auth/sign-in`, {
341
352
  method: "POST",
342
353
  credentials: "include",
343
- headers: { "Content-Type": "application/json" },
354
+ headers: {
355
+ "Content-Type": "application/json",
356
+ ...pk ? { "x-vaultix-pk": pk } : {}
357
+ },
344
358
  body: JSON.stringify({ email, password })
345
359
  });
346
360
  const data = await res.json();
@@ -365,7 +379,7 @@ function SignIn({
365
379
  setLoading(true);
366
380
  try {
367
381
  const optRes = await fetch(
368
- `${apiOrigin}/v1/auth/passkey/authenticate/options`,
382
+ `${apiOrigin}/api/v1/auth/passkey/authenticate/options`,
369
383
  {
370
384
  method: "POST",
371
385
  credentials: "include",
@@ -382,7 +396,7 @@ function SignIn({
382
396
  publicKey: options
383
397
  });
384
398
  const verifyRes = await fetch(
385
- `${apiOrigin}/v1/auth/passkey/authenticate/verify`,
399
+ `${apiOrigin}/api/v1/auth/passkey/authenticate/verify`,
386
400
  {
387
401
  method: "POST",
388
402
  credentials: "include",
@@ -425,7 +439,7 @@ function SignIn({
425
439
  setError(null);
426
440
  setLoading(true);
427
441
  try {
428
- const res = await fetch(`${apiOrigin}/v1/auth/totp/verify`, {
442
+ const res = await fetch(`${apiOrigin}/api/v1/auth/totp/verify`, {
429
443
  method: "POST",
430
444
  credentials: "include",
431
445
  headers: { "Content-Type": "application/json" },
@@ -448,7 +462,7 @@ function SignIn({
448
462
  setError(null);
449
463
  setLoading(true);
450
464
  try {
451
- await fetch(`${apiOrigin}/v1/auth/forgot-password`, {
465
+ await fetch(`${apiOrigin}/api/v1/auth/forgot-password`, {
452
466
  method: "POST",
453
467
  credentials: "include",
454
468
  headers: { "Content-Type": "application/json" },
@@ -473,7 +487,7 @@ function SignIn({
473
487
  setError(null);
474
488
  setLoading(true);
475
489
  try {
476
- const res = await fetch(`${apiOrigin}/v1/auth/reset-password`, {
490
+ const res = await fetch(`${apiOrigin}/api/v1/auth/reset-password`, {
477
491
  method: "POST",
478
492
  credentials: "include",
479
493
  headers: { "Content-Type": "application/json" },
@@ -829,14 +843,14 @@ function SignUp({
829
843
  function handleGoogleSignUp() {
830
844
  const target = resolveAfterSignUpUrl(redirectUrl);
831
845
  const params = new URLSearchParams({ redirect_url: target });
832
- window.location.href = `${apiOrigin}/v1/auth/oauth/google?${params}`;
846
+ window.location.href = `${apiOrigin}/api/v1/auth/oauth/google?${params}`;
833
847
  }
834
848
  async function handleEmailPassword(e) {
835
849
  e.preventDefault();
836
850
  setError(null);
837
851
  setLoading(true);
838
852
  try {
839
- const res = await fetch(`${apiOrigin}/v1/auth/sign-up`, {
853
+ const res = await fetch(`${apiOrigin}/api/v1/auth/sign-up`, {
840
854
  method: "POST",
841
855
  credentials: "include",
842
856
  headers: { "Content-Type": "application/json" },
@@ -860,7 +874,7 @@ function SignUp({
860
874
  setError(null);
861
875
  setLoading(true);
862
876
  try {
863
- const res = await fetch(`${apiOrigin}/v1/auth/email/verify`, {
877
+ const res = await fetch(`${apiOrigin}/api/v1/auth/email/verify`, {
864
878
  method: "POST",
865
879
  credentials: "include",
866
880
  headers: { "Content-Type": "application/json" },
@@ -884,7 +898,7 @@ function SignUp({
884
898
  async function resendCode() {
885
899
  if (!registrationId) return;
886
900
  try {
887
- await fetch(`${apiOrigin}/v1/auth/email/resend`, {
901
+ await fetch(`${apiOrigin}/api/v1/auth/email/resend`, {
888
902
  method: "POST",
889
903
  credentials: "include",
890
904
  headers: { "Content-Type": "application/json" },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaultix.ai/react",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Vaultix-ID React SDK — drop-in auth components for any React app",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",