@instroc/auth 1.1.0 → 1.1.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.
@@ -27,10 +27,34 @@ function authErrorFromResponse(response, data, fallbackMessage) {
27
27
  return new AuthError(message, response.status, body.code);
28
28
  }
29
29
 
30
+ // src/version.ts
31
+ var SDK_NAME = "instroc-auth";
32
+ var SDK_VERSION = true ? "1.1.1" : "0.0.0-dev";
33
+ function withSdkHeader(init) {
34
+ const headers = new Headers(init?.headers ?? {});
35
+ headers.set("X-Instroc-SDK", `${SDK_NAME}/${SDK_VERSION}`);
36
+ return { ...init, headers };
37
+ }
38
+
30
39
  // src/provider.tsx
31
40
  import { jsx } from "react/jsx-runtime";
32
41
  var AuthContext = createContext(null);
33
42
  var STORAGE_KEY = "instroc_auth_session";
43
+ var WARNING_SESSION_KEY = "instroc_auth_sdk_warning_seen";
44
+ function noteDeprecationWarning(response) {
45
+ const warning = response.headers.get("X-Instroc-SDK-Warning");
46
+ if (!warning)
47
+ return;
48
+ if (typeof window === "undefined")
49
+ return;
50
+ try {
51
+ if (sessionStorage.getItem(WARNING_SESSION_KEY))
52
+ return;
53
+ sessionStorage.setItem(WARNING_SESSION_KEY, "1");
54
+ } catch {
55
+ }
56
+ console.warn(`[instroc-auth] ${warning}`);
57
+ }
34
58
  function AuthProvider({
35
59
  children,
36
60
  projectId: initialProjectId,
@@ -57,10 +81,14 @@ function AuthProvider({
57
81
  },
58
82
  [projectId, baseUrl]
59
83
  );
60
- const authFetch = useCallback(
61
- (url, init) => fetch(url, { ...init, credentials: "include" }),
62
- []
63
- );
84
+ const authFetch = useCallback(async (url, init) => {
85
+ const response = await fetch(url, {
86
+ ...withSdkHeader(init),
87
+ credentials: "include"
88
+ });
89
+ noteDeprecationWarning(response);
90
+ return response;
91
+ }, []);
64
92
  const saveSession = useCallback(
65
93
  (sessionData) => {
66
94
  if (persistSession && typeof window !== "undefined") {
@@ -433,7 +461,11 @@ function AuthProvider({
433
461
  if (!projectId)
434
462
  return;
435
463
  try {
436
- const response = await fetch(`${baseUrl}/${projectId}/auth/config`);
464
+ const response = await fetch(
465
+ `${baseUrl}/${projectId}/auth/config`,
466
+ withSdkHeader()
467
+ );
468
+ noteDeprecationWarning(response);
437
469
  if (response.ok) {
438
470
  const data = await response.json();
439
471
  setAuthConfig(data.config || null);
@@ -476,11 +508,14 @@ function AuthProvider({
476
508
  const params = new URLSearchParams(window.location.search);
477
509
  const verifyEmailToken = params.get("verify_email");
478
510
  if (verifyEmailToken && projectId) {
479
- fetch(buildUrl("verify-email"), {
480
- method: "POST",
481
- headers: { "Content-Type": "application/json" },
482
- body: JSON.stringify({ token: verifyEmailToken })
483
- }).then((res) => res.json()).then(() => {
511
+ fetch(
512
+ buildUrl("verify-email"),
513
+ withSdkHeader({
514
+ method: "POST",
515
+ headers: { "Content-Type": "application/json" },
516
+ body: JSON.stringify({ token: verifyEmailToken })
517
+ })
518
+ ).then((res) => res.json()).then(() => {
484
519
  window.history.replaceState({}, "", window.location.pathname);
485
520
  }).catch(() => {
486
521
  window.history.replaceState({}, "", window.location.pathname);
package/dist/forms.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  useOtpForm,
5
5
  useResetPasswordForm,
6
6
  useSignupForm
7
- } from "./chunk-GV63J77S.js";
7
+ } from "./chunk-T7NGX4DQ.js";
8
8
  export {
9
9
  useForgotPasswordForm,
10
10
  useLoginForm,
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  useSession,
12
12
  useSignupForm,
13
13
  useUser
14
- } from "./chunk-GV63J77S.js";
14
+ } from "./chunk-T7NGX4DQ.js";
15
15
  export {
16
16
  AuthError,
17
17
  AuthProvider,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instroc/auth",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Authentication hooks for Instroc Cloud — useAuth, useUser, AuthProvider, and headless form hooks",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",