@vaultix.ai/react 0.2.4 → 0.3.1

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
@@ -170,21 +170,22 @@ function VaultixProvider({
170
170
  }
171
171
  jwtRef.current = jwt;
172
172
  }
173
+ if (!jwt) {
174
+ if (!cancelled) setIsLoaded(true);
175
+ return;
176
+ }
173
177
  try {
174
178
  const headers = {
179
+ "Authorization": `Bearer ${jwt}`,
175
180
  "X-Vaultix-Publishable-Key": publishableKey
176
181
  };
177
- if (jwt) headers["Authorization"] = `Bearer ${jwt}`;
178
182
  const res = await fetch(`${apiOrigin}/api/v1/me`, {
179
- // Use Bearer token for cross-domain; fall back to cookie for same-domain
180
- credentials: jwt ? "omit" : "include",
183
+ credentials: "omit",
181
184
  headers
182
185
  });
183
186
  if (!res.ok) {
184
- if (jwt) {
185
- clearJwt();
186
- jwtRef.current = null;
187
- }
187
+ clearJwt();
188
+ jwtRef.current = null;
188
189
  if (!cancelled) setIsLoaded(true);
189
190
  return;
190
191
  }
@@ -210,16 +211,14 @@ function VaultixProvider({
210
211
  const jwt = jwtRef.current;
211
212
  clearAuth();
212
213
  if (refreshTimerRef.current) clearTimeout(refreshTimerRef.current);
213
- try {
214
- const headers = {};
215
- if (jwt) headers["Authorization"] = `Bearer ${jwt}`;
216
- await fetch(`${apiOrigin}/api/v1/session`, {
217
- method: "DELETE",
218
- credentials: jwt ? "omit" : "include",
219
- headers
220
- });
221
- } catch {
222
- }
214
+ const headers = {};
215
+ if (jwt) headers["Authorization"] = `Bearer ${jwt}`;
216
+ fetch(`${apiOrigin}/api/v1/session`, {
217
+ method: "DELETE",
218
+ credentials: jwt ? "omit" : "include",
219
+ headers
220
+ }).catch(() => {
221
+ });
223
222
  if (afterSignInUrl) window.location.href = afterSignInUrl;
224
223
  }, [apiOrigin, afterSignInUrl, clearAuth]);
225
224
  const value = {
@@ -344,13 +343,18 @@ function SignIn({
344
343
  url.searchParams.set("__vaultix_handshake", handshakeToken);
345
344
  window.location.href = url.toString();
346
345
  }
347
- function handleGoogleSignIn() {
346
+ function oauthRedirect(provider) {
348
347
  const target = resolveAfterSignInUrl(redirectUrl);
349
348
  const pk = resolvePk();
350
349
  const params = new URLSearchParams({ redirect_url: target });
351
350
  if (pk) params.set("pk", pk);
352
- window.location.href = `${apiOrigin}/api/v1/auth/oauth/google?${params}`;
351
+ window.location.href = `${apiOrigin}/api/v1/auth/oauth/${provider}?${params}`;
353
352
  }
353
+ const handleGoogleSignIn = () => oauthRedirect("google");
354
+ const handleMetaSignIn = () => oauthRedirect("meta");
355
+ const handleLinkedInSignIn = () => oauthRedirect("linkedin");
356
+ const handleXSignIn = () => oauthRedirect("x");
357
+ const handleGitHubSignIn = () => oauthRedirect("github");
354
358
  async function handleEmailSubmit(e) {
355
359
  e.preventDefault();
356
360
  setError(null);
@@ -575,6 +579,10 @@ function SignIn({
575
579
  info && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "rounded-lg bg-blue-500/10 border border-blue-500/30 px-3 py-2", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "text-xs text-blue-400", children: info }) }),
576
580
  step === "email" && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "space-y-3", children: [
577
581
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(GoogleButton, { onClick: handleGoogleSignIn }),
582
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(GitHubButton, { onClick: handleGitHubSignIn }),
583
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MetaButton, { onClick: handleMetaSignIn }),
584
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(LinkedInButton, { onClick: handleLinkedInSignIn }),
585
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(XButton, { onClick: handleXSignIn }),
578
586
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Divider, {}),
579
587
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("form", { onSubmit: handleEmailSubmit, className: "space-y-3", children: [
580
588
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
@@ -740,7 +748,11 @@ function GhostButton({ children, onClick }) {
740
748
  }
741
749
  );
742
750
  }
743
- function GoogleButton({ onClick }) {
751
+ function OAuthButton({
752
+ icon,
753
+ label,
754
+ onClick
755
+ }) {
744
756
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
745
757
  "button",
746
758
  {
@@ -754,12 +766,27 @@ function GoogleButton({ onClick }) {
754
766
  "transition-all duration-150"
755
767
  ),
756
768
  children: [
757
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(GoogleIcon, {}),
758
- "Continue with Google"
769
+ icon,
770
+ label
759
771
  ]
760
772
  }
761
773
  );
762
774
  }
775
+ function GoogleButton({ onClick }) {
776
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(OAuthButton, { icon: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(GoogleIcon, {}), label: "Continue with Google", onClick });
777
+ }
778
+ function MetaButton({ onClick }) {
779
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(OAuthButton, { icon: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MetaIcon, {}), label: "Continue with Facebook", onClick });
780
+ }
781
+ function LinkedInButton({ onClick }) {
782
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(OAuthButton, { icon: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(LinkedInIcon, {}), label: "Continue with LinkedIn", onClick });
783
+ }
784
+ function GitHubButton({ onClick }) {
785
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(OAuthButton, { icon: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(GitHubIcon, {}), label: "Continue with GitHub", onClick });
786
+ }
787
+ function XButton({ onClick }) {
788
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(OAuthButton, { icon: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(XIcon, {}), label: "Continue with X", onClick });
789
+ }
763
790
  function Divider() {
764
791
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "flex items-center gap-3", children: [
765
792
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "flex-1 h-px bg-white/8" }),
@@ -821,6 +848,18 @@ function GoogleIcon() {
821
848
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z", fill: "#EA4335" })
822
849
  ] });
823
850
  }
851
+ function MetaIcon() {
852
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "#1877F2", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z" }) });
853
+ }
854
+ function LinkedInIcon() {
855
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "#0A66C2", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433a2.062 2.062 0 01-2.063-2.065 2.063 2.063 0 112.063 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z" }) });
856
+ }
857
+ function GitHubIcon() {
858
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "white", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0 1 12 6.844a9.59 9.59 0 0 1 2.504.337c1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.02 10.02 0 0 0 22 12.017C22 6.484 17.522 2 12 2z" }) });
859
+ }
860
+ function XIcon() {
861
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "white", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-4.714-6.231-5.401 6.231H2.744l7.737-8.835L1.254 2.25H8.08l4.253 5.622 5.911-5.622zm-1.161 17.52h1.833L7.084 4.126H5.117z" }) });
862
+ }
824
863
 
825
864
  // src/components/SignUp.tsx
826
865
  var import_clsx2 = require("clsx");
package/dist/index.mjs CHANGED
@@ -138,21 +138,22 @@ function VaultixProvider({
138
138
  }
139
139
  jwtRef.current = jwt;
140
140
  }
141
+ if (!jwt) {
142
+ if (!cancelled) setIsLoaded(true);
143
+ return;
144
+ }
141
145
  try {
142
146
  const headers = {
147
+ "Authorization": `Bearer ${jwt}`,
143
148
  "X-Vaultix-Publishable-Key": publishableKey
144
149
  };
145
- if (jwt) headers["Authorization"] = `Bearer ${jwt}`;
146
150
  const res = await fetch(`${apiOrigin}/api/v1/me`, {
147
- // Use Bearer token for cross-domain; fall back to cookie for same-domain
148
- credentials: jwt ? "omit" : "include",
151
+ credentials: "omit",
149
152
  headers
150
153
  });
151
154
  if (!res.ok) {
152
- if (jwt) {
153
- clearJwt();
154
- jwtRef.current = null;
155
- }
155
+ clearJwt();
156
+ jwtRef.current = null;
156
157
  if (!cancelled) setIsLoaded(true);
157
158
  return;
158
159
  }
@@ -178,16 +179,14 @@ function VaultixProvider({
178
179
  const jwt = jwtRef.current;
179
180
  clearAuth();
180
181
  if (refreshTimerRef.current) clearTimeout(refreshTimerRef.current);
181
- try {
182
- const headers = {};
183
- if (jwt) headers["Authorization"] = `Bearer ${jwt}`;
184
- await fetch(`${apiOrigin}/api/v1/session`, {
185
- method: "DELETE",
186
- credentials: jwt ? "omit" : "include",
187
- headers
188
- });
189
- } catch {
190
- }
182
+ const headers = {};
183
+ if (jwt) headers["Authorization"] = `Bearer ${jwt}`;
184
+ fetch(`${apiOrigin}/api/v1/session`, {
185
+ method: "DELETE",
186
+ credentials: jwt ? "omit" : "include",
187
+ headers
188
+ }).catch(() => {
189
+ });
191
190
  if (afterSignInUrl) window.location.href = afterSignInUrl;
192
191
  }, [apiOrigin, afterSignInUrl, clearAuth]);
193
192
  const value = {
@@ -312,13 +311,18 @@ function SignIn({
312
311
  url.searchParams.set("__vaultix_handshake", handshakeToken);
313
312
  window.location.href = url.toString();
314
313
  }
315
- function handleGoogleSignIn() {
314
+ function oauthRedirect(provider) {
316
315
  const target = resolveAfterSignInUrl(redirectUrl);
317
316
  const pk = resolvePk();
318
317
  const params = new URLSearchParams({ redirect_url: target });
319
318
  if (pk) params.set("pk", pk);
320
- window.location.href = `${apiOrigin}/api/v1/auth/oauth/google?${params}`;
319
+ window.location.href = `${apiOrigin}/api/v1/auth/oauth/${provider}?${params}`;
321
320
  }
321
+ const handleGoogleSignIn = () => oauthRedirect("google");
322
+ const handleMetaSignIn = () => oauthRedirect("meta");
323
+ const handleLinkedInSignIn = () => oauthRedirect("linkedin");
324
+ const handleXSignIn = () => oauthRedirect("x");
325
+ const handleGitHubSignIn = () => oauthRedirect("github");
322
326
  async function handleEmailSubmit(e) {
323
327
  e.preventDefault();
324
328
  setError(null);
@@ -543,6 +547,10 @@ function SignIn({
543
547
  info && /* @__PURE__ */ jsx2("div", { className: "rounded-lg bg-blue-500/10 border border-blue-500/30 px-3 py-2", children: /* @__PURE__ */ jsx2("p", { className: "text-xs text-blue-400", children: info }) }),
544
548
  step === "email" && /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
545
549
  /* @__PURE__ */ jsx2(GoogleButton, { onClick: handleGoogleSignIn }),
550
+ /* @__PURE__ */ jsx2(GitHubButton, { onClick: handleGitHubSignIn }),
551
+ /* @__PURE__ */ jsx2(MetaButton, { onClick: handleMetaSignIn }),
552
+ /* @__PURE__ */ jsx2(LinkedInButton, { onClick: handleLinkedInSignIn }),
553
+ /* @__PURE__ */ jsx2(XButton, { onClick: handleXSignIn }),
546
554
  /* @__PURE__ */ jsx2(Divider, {}),
547
555
  /* @__PURE__ */ jsxs("form", { onSubmit: handleEmailSubmit, className: "space-y-3", children: [
548
556
  /* @__PURE__ */ jsx2(
@@ -708,7 +716,11 @@ function GhostButton({ children, onClick }) {
708
716
  }
709
717
  );
710
718
  }
711
- function GoogleButton({ onClick }) {
719
+ function OAuthButton({
720
+ icon,
721
+ label,
722
+ onClick
723
+ }) {
712
724
  return /* @__PURE__ */ jsxs(
713
725
  "button",
714
726
  {
@@ -722,12 +734,27 @@ function GoogleButton({ onClick }) {
722
734
  "transition-all duration-150"
723
735
  ),
724
736
  children: [
725
- /* @__PURE__ */ jsx2(GoogleIcon, {}),
726
- "Continue with Google"
737
+ icon,
738
+ label
727
739
  ]
728
740
  }
729
741
  );
730
742
  }
743
+ function GoogleButton({ onClick }) {
744
+ return /* @__PURE__ */ jsx2(OAuthButton, { icon: /* @__PURE__ */ jsx2(GoogleIcon, {}), label: "Continue with Google", onClick });
745
+ }
746
+ function MetaButton({ onClick }) {
747
+ return /* @__PURE__ */ jsx2(OAuthButton, { icon: /* @__PURE__ */ jsx2(MetaIcon, {}), label: "Continue with Facebook", onClick });
748
+ }
749
+ function LinkedInButton({ onClick }) {
750
+ return /* @__PURE__ */ jsx2(OAuthButton, { icon: /* @__PURE__ */ jsx2(LinkedInIcon, {}), label: "Continue with LinkedIn", onClick });
751
+ }
752
+ function GitHubButton({ onClick }) {
753
+ return /* @__PURE__ */ jsx2(OAuthButton, { icon: /* @__PURE__ */ jsx2(GitHubIcon, {}), label: "Continue with GitHub", onClick });
754
+ }
755
+ function XButton({ onClick }) {
756
+ return /* @__PURE__ */ jsx2(OAuthButton, { icon: /* @__PURE__ */ jsx2(XIcon, {}), label: "Continue with X", onClick });
757
+ }
731
758
  function Divider() {
732
759
  return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
733
760
  /* @__PURE__ */ jsx2("div", { className: "flex-1 h-px bg-white/8" }),
@@ -789,6 +816,18 @@ function GoogleIcon() {
789
816
  /* @__PURE__ */ jsx2("path", { d: "M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z", fill: "#EA4335" })
790
817
  ] });
791
818
  }
819
+ function MetaIcon() {
820
+ return /* @__PURE__ */ jsx2("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "#1877F2", children: /* @__PURE__ */ jsx2("path", { d: "M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z" }) });
821
+ }
822
+ function LinkedInIcon() {
823
+ return /* @__PURE__ */ jsx2("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "#0A66C2", children: /* @__PURE__ */ jsx2("path", { d: "M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433a2.062 2.062 0 01-2.063-2.065 2.063 2.063 0 112.063 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z" }) });
824
+ }
825
+ function GitHubIcon() {
826
+ return /* @__PURE__ */ jsx2("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "white", children: /* @__PURE__ */ jsx2("path", { d: "M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0 1 12 6.844a9.59 9.59 0 0 1 2.504.337c1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.02 10.02 0 0 0 22 12.017C22 6.484 17.522 2 12 2z" }) });
827
+ }
828
+ function XIcon() {
829
+ return /* @__PURE__ */ jsx2("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "white", children: /* @__PURE__ */ jsx2("path", { d: "M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-4.714-6.231-5.401 6.231H2.744l7.737-8.835L1.254 2.25H8.08l4.253 5.622 5.911-5.622zm-1.161 17.52h1.833L7.084 4.126H5.117z" }) });
830
+ }
792
831
 
793
832
  // src/components/SignUp.tsx
794
833
  import { clsx as clsx2 } from "clsx";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaultix.ai/react",
3
- "version": "0.2.4",
3
+ "version": "0.3.1",
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",