@arcote.tech/arc-auth 0.7.16 → 0.7.17
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcote.tech/arc-auth",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.17",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Reusable authentication module for Arc framework — aggregate-based auth with factory pattern",
|
|
7
7
|
"main": "./src/index.ts",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"type-check": "tsc --noEmit"
|
|
11
11
|
},
|
|
12
12
|
"peerDependencies": {
|
|
13
|
-
"@arcote.tech/arc": "^0.7.
|
|
14
|
-
"@arcote.tech/platform": "^0.7.
|
|
13
|
+
"@arcote.tech/arc": "^0.7.17",
|
|
14
|
+
"@arcote.tech/platform": "^0.7.17",
|
|
15
15
|
"react": "^18.0.0 || ^19.0.0",
|
|
16
16
|
"typescript": "^5.0.0"
|
|
17
17
|
},
|
package/src/react/auth-page.tsx
CHANGED
|
@@ -78,8 +78,10 @@ export function AuthPage({
|
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
// Await module-chunk sync for the new token before navigating, so a
|
|
82
|
+
// redirect into a token-gated route resolves (no arbitrary delay).
|
|
83
|
+
await setAccessToken(result.token);
|
|
84
|
+
navigate(redirectTo);
|
|
83
85
|
} catch (err) {
|
|
84
86
|
console.error("[AuthPage] signIn error:", err);
|
|
85
87
|
setError("Nie udało się połączyć z serwerem.");
|
|
@@ -10,7 +10,9 @@ export interface AuthContextType {
|
|
|
10
10
|
token: string | null;
|
|
11
11
|
isAuthenticated: boolean;
|
|
12
12
|
isLoading: boolean;
|
|
13
|
-
|
|
13
|
+
/** Resolves when the module loader has synced chunks for the new token —
|
|
14
|
+
* await before navigating to a token-gated route. */
|
|
15
|
+
setAccessToken: (token: string) => Promise<void>;
|
|
14
16
|
logout: () => void;
|
|
15
17
|
}
|
|
16
18
|
|
|
@@ -18,8 +20,10 @@ const AuthContext = createContext<AuthContextType | null>(null);
|
|
|
18
20
|
|
|
19
21
|
export interface AuthProviderProps {
|
|
20
22
|
children: ReactNode;
|
|
21
|
-
/** Callback to set token on the arc model (
|
|
22
|
-
|
|
23
|
+
/** Callback to set token on the arc model (scope.setToken from reactModel).
|
|
24
|
+
* May return a promise that resolves when module chunks for the new token
|
|
25
|
+
* have loaded — forwarded by setAccessToken so callers can await it. */
|
|
26
|
+
onTokenChange?: (token: string | null) => void | Promise<void>;
|
|
23
27
|
/** Initial token from scope (loaded by adapter.loadPersisted on model init) */
|
|
24
28
|
initialToken?: string | null;
|
|
25
29
|
}
|
|
@@ -50,9 +54,10 @@ export function AuthProvider({ children, onTokenChange, initialToken }: AuthProv
|
|
|
50
54
|
setIsLoading(false);
|
|
51
55
|
}, []);
|
|
52
56
|
|
|
53
|
-
const setAccessToken = (newToken: string) => {
|
|
57
|
+
const setAccessToken = async (newToken: string): Promise<void> => {
|
|
54
58
|
setToken(newToken);
|
|
55
|
-
|
|
59
|
+
// scope.setToken → adapter auto-persists + awaits module-chunk sync
|
|
60
|
+
await onTokenChange?.(newToken);
|
|
56
61
|
};
|
|
57
62
|
|
|
58
63
|
const logout = () => {
|
|
@@ -55,8 +55,10 @@ export function SignInPage({ signIn, navigate, render }: SignInPageProps) {
|
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
// Await module-chunk sync for the new token before navigating, so a
|
|
59
|
+
// redirect into a token-gated route resolves (no arbitrary delay).
|
|
60
|
+
await setAccessToken(result.token);
|
|
61
|
+
navigate(redirectTo);
|
|
60
62
|
} catch (err) {
|
|
61
63
|
console.error("[SignInPage] signIn error:", err);
|
|
62
64
|
setError("Nie udało się połączyć z serwerem.");
|