autherr 2.0.32 → 2.0.34
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.
|
@@ -21,26 +21,34 @@ export function AutherrProvider({ children, clientId, baseUrl, clientPrivateKey,
|
|
|
21
21
|
useEffect(() => {
|
|
22
22
|
refreshSession();
|
|
23
23
|
}, [baseUrl, clientId]);
|
|
24
|
+
// FIXED: Removed duplicate nested buildRedirect function that was causing multiple backend requests
|
|
25
|
+
// OLD CODE (commented out):
|
|
26
|
+
// const buildRedirect = async (path: "login" | "signup") => {
|
|
27
|
+
// const state = crypto.randomUUID();
|
|
28
|
+
// const assertion = await createClientAssertion(clientId, clientPrivateKey);
|
|
29
|
+
// const url = new URL(`${baseUrl}/auth/${path}`);
|
|
30
|
+
// url.searchParams.set("client_id", clientId);
|
|
31
|
+
// url.searchParams.set("redirect_uri", window.location.origin);
|
|
32
|
+
// url.searchParams.set("state", state);
|
|
33
|
+
// // Had a nested duplicate buildRedirect here causing the issue
|
|
34
|
+
// const buildRedirect = async (path: "login" | "signup") => { ... }
|
|
35
|
+
// };
|
|
36
|
+
// const login = () => buildRedirect("login");
|
|
37
|
+
// const signup = () => buildRedirect("signup");
|
|
38
|
+
// NEW FINAL CODE:
|
|
24
39
|
const buildRedirect = async (path) => {
|
|
25
40
|
const state = crypto.randomUUID();
|
|
26
41
|
const assertion = await createClientAssertion(clientId, clientPrivateKey);
|
|
42
|
+
// Persist assertion temporarily (cookie / storage / backend exchange)
|
|
43
|
+
sessionStorage.setItem("client_assertion", assertion);
|
|
27
44
|
const url = new URL(`${baseUrl}/auth/${path}`);
|
|
28
45
|
url.searchParams.set("client_id", clientId);
|
|
29
46
|
url.searchParams.set("redirect_uri", window.location.origin);
|
|
30
47
|
url.searchParams.set("state", state);
|
|
31
|
-
|
|
32
|
-
await fetch(url.toString(), {
|
|
33
|
-
method: "GET",
|
|
34
|
-
headers: {
|
|
35
|
-
"X-Client-Assertion": assertion,
|
|
36
|
-
},
|
|
37
|
-
credentials: "include",
|
|
38
|
-
}).then((res) => {
|
|
39
|
-
window.location.href = res.url;
|
|
40
|
-
});
|
|
48
|
+
window.location.href = url.toString();
|
|
41
49
|
};
|
|
42
|
-
const login = () => buildRedirect("login");
|
|
43
|
-
const signup = () => buildRedirect("signup");
|
|
50
|
+
const login = async () => buildRedirect("login");
|
|
51
|
+
const signup = async () => buildRedirect("signup");
|
|
44
52
|
const logout = async () => {
|
|
45
53
|
await logoutSession(baseUrl, clientId);
|
|
46
54
|
setAccessToken(null);
|
package/package.json
CHANGED
|
@@ -52,6 +52,22 @@ export function AutherrProvider({
|
|
|
52
52
|
refreshSession();
|
|
53
53
|
}, [baseUrl, clientId]);
|
|
54
54
|
|
|
55
|
+
// FIXED: Removed duplicate nested buildRedirect function that was causing multiple backend requests
|
|
56
|
+
// OLD CODE (commented out):
|
|
57
|
+
// const buildRedirect = async (path: "login" | "signup") => {
|
|
58
|
+
// const state = crypto.randomUUID();
|
|
59
|
+
// const assertion = await createClientAssertion(clientId, clientPrivateKey);
|
|
60
|
+
// const url = new URL(`${baseUrl}/auth/${path}`);
|
|
61
|
+
// url.searchParams.set("client_id", clientId);
|
|
62
|
+
// url.searchParams.set("redirect_uri", window.location.origin);
|
|
63
|
+
// url.searchParams.set("state", state);
|
|
64
|
+
// // Had a nested duplicate buildRedirect here causing the issue
|
|
65
|
+
// const buildRedirect = async (path: "login" | "signup") => { ... }
|
|
66
|
+
// };
|
|
67
|
+
// const login = () => buildRedirect("login");
|
|
68
|
+
// const signup = () => buildRedirect("signup");
|
|
69
|
+
|
|
70
|
+
// NEW FINAL CODE:
|
|
55
71
|
const buildRedirect = async (path: "login" | "signup") => {
|
|
56
72
|
const state = crypto.randomUUID();
|
|
57
73
|
|
|
@@ -60,29 +76,19 @@ export function AutherrProvider({
|
|
|
60
76
|
clientPrivateKey
|
|
61
77
|
);
|
|
62
78
|
|
|
79
|
+
// Persist assertion temporarily (cookie / storage / backend exchange)
|
|
80
|
+
sessionStorage.setItem("client_assertion", assertion);
|
|
81
|
+
|
|
63
82
|
const url = new URL(`${baseUrl}/auth/${path}`);
|
|
64
83
|
url.searchParams.set("client_id", clientId);
|
|
65
|
-
url.searchParams.set(
|
|
66
|
-
"redirect_uri",
|
|
67
|
-
window.location.origin
|
|
68
|
-
);
|
|
84
|
+
url.searchParams.set("redirect_uri", window.location.origin);
|
|
69
85
|
url.searchParams.set("state", state);
|
|
70
86
|
|
|
71
|
-
|
|
72
|
-
await fetch(url.toString(), {
|
|
73
|
-
method: "GET",
|
|
74
|
-
headers: {
|
|
75
|
-
"X-Client-Id": clientId,
|
|
76
|
-
"X-Client-Assertion": assertion,
|
|
77
|
-
},
|
|
78
|
-
credentials: "include",
|
|
79
|
-
}).then((res) => {
|
|
80
|
-
window.location.href = res.url;
|
|
81
|
-
});
|
|
87
|
+
window.location.href = url.toString();
|
|
82
88
|
};
|
|
83
89
|
|
|
84
|
-
const login = () => buildRedirect("login");
|
|
85
|
-
const signup = () => buildRedirect("signup");
|
|
90
|
+
const login = async () => buildRedirect("login");
|
|
91
|
+
const signup = async () => buildRedirect("signup");
|
|
86
92
|
|
|
87
93
|
const logout = async () => {
|
|
88
94
|
await logoutSession(baseUrl, clientId);
|