@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.
- package/dist/{chunk-GV63J77S.js → chunk-T7NGX4DQ.js} +45 -10
- package/dist/forms.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -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
|
-
|
|
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(
|
|
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(
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
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
package/dist/index.js
CHANGED