@checkstack/auth-frontend 0.2.0 → 0.3.0
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/CHANGELOG.md +62 -0
- package/package.json +1 -1
- package/src/components/ApplicationsTab.tsx +88 -89
- package/src/components/AuthSettingsPage.tsx +60 -50
- package/src/components/LoginPage.tsx +7 -15
- package/src/components/RegisterPage.tsx +12 -20
- package/src/components/RoleDialog.tsx +12 -16
- package/src/components/RolesTab.tsx +52 -39
- package/src/components/StrategiesTab.tsx +88 -94
- package/src/components/TeamAccessEditor.tsx +125 -114
- package/src/components/TeamsTab.tsx +179 -161
- package/src/components/UsersTab.tsx +41 -30
- package/src/hooks/useAccessRules.ts +23 -34
- package/src/hooks/useEnabledStrategies.ts +10 -41
- package/src/lib/auth-client.ts +17 -22
package/src/lib/auth-client.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
2
|
import { createAuthClient } from "better-auth/react";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
useRuntimeConfig,
|
|
5
|
+
getCachedRuntimeConfig,
|
|
6
|
+
} from "@checkstack/frontend-api";
|
|
4
7
|
|
|
5
8
|
// Cache for lazy-initialized client
|
|
6
9
|
let cachedClient: ReturnType<typeof createAuthClient> | undefined;
|
|
7
|
-
let
|
|
10
|
+
let cachedBaseUrl: string | undefined;
|
|
8
11
|
|
|
9
12
|
/**
|
|
10
13
|
* React hook to get the auth client with proper runtime config.
|
|
@@ -25,31 +28,23 @@ export function useAuthClient() {
|
|
|
25
28
|
|
|
26
29
|
/**
|
|
27
30
|
* Lazy-initialized auth client for class-based APIs.
|
|
28
|
-
*
|
|
29
|
-
*
|
|
31
|
+
* Uses the cached runtime config from RuntimeConfigProvider.
|
|
32
|
+
*
|
|
33
|
+
* Note: This should only be called AFTER RuntimeConfigProvider has loaded.
|
|
34
|
+
* Components rendered inside the provider tree are guaranteed to have config available.
|
|
30
35
|
*/
|
|
31
36
|
export function getAuthClientLazy(): ReturnType<typeof createAuthClient> {
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
const config = getCachedRuntimeConfig();
|
|
38
|
+
const baseUrl = config?.baseUrl ?? "http://localhost:3000";
|
|
39
|
+
|
|
40
|
+
// Recreate client if baseUrl changed or not yet created
|
|
41
|
+
if (!cachedClient || cachedBaseUrl !== baseUrl) {
|
|
42
|
+
cachedBaseUrl = baseUrl;
|
|
34
43
|
cachedClient = createAuthClient({
|
|
35
|
-
baseURL:
|
|
44
|
+
baseURL: baseUrl,
|
|
36
45
|
basePath: "/api/auth",
|
|
37
46
|
});
|
|
38
|
-
|
|
39
|
-
// Fetch real config and update
|
|
40
|
-
if (!configPromise) {
|
|
41
|
-
configPromise = fetch("/api/config")
|
|
42
|
-
.then((res) => res.json())
|
|
43
|
-
.then((data: { baseUrl: string }) => data.baseUrl)
|
|
44
|
-
.catch(() => "http://localhost:3000");
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
configPromise.then((baseUrl) => {
|
|
48
|
-
cachedClient = createAuthClient({
|
|
49
|
-
baseURL: baseUrl,
|
|
50
|
-
basePath: "/api/auth",
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
47
|
}
|
|
48
|
+
|
|
54
49
|
return cachedClient;
|
|
55
50
|
}
|