@uipath/apollo-vertex 0.4.0 → 1.0.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/README.md +2 -2
- package/dist/entries/index.d.ts +1 -1
- package/dist/entries/index.js +2 -2
- package/dist/lib/auth.d.ts +5 -2
- package/dist/lib/auth.js +76 -43
- package/dist/registry/shell/shell-auth-provider.d.ts +2 -1
- package/dist/registry/shell/shell-auth-provider.js +7 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,14 +27,14 @@ Everything, including the app shell, charts, feature flags, Solution Tests and A
|
|
|
27
27
|
from the package root. Translation JSON files are available at `@uipath/apollo-vertex/locales/*`.
|
|
28
28
|
|
|
29
29
|
npm 7+ and pnpm install the packages in `peerDependencies` automatically. Install these three
|
|
30
|
-
yourself
|
|
30
|
+
yourself:
|
|
31
31
|
|
|
32
32
|
- `@uipath/vs-core`
|
|
33
33
|
- `@tanstack/react-db`
|
|
34
34
|
- `@uipath/proteus-client`
|
|
35
35
|
|
|
36
36
|
They are declared only in `peerDependenciesMeta` (as optional) so that pnpm does not try to install them
|
|
37
|
-
in this workspace.
|
|
37
|
+
in this workspace. The two `@uipath` packages are not on the public npm registry.
|
|
38
38
|
|
|
39
39
|
## Layout
|
|
40
40
|
|
package/dist/entries/index.d.ts
CHANGED
|
@@ -94,7 +94,7 @@ export { ShellLayout } from "../registry/shell/shell-layout";
|
|
|
94
94
|
export { ShellSidebar } from "../registry/shell/shell-sidebar";
|
|
95
95
|
export { ShellUserProvider, useUser, type User, } from "../registry/shell/shell-user-provider";
|
|
96
96
|
export { SUPPORTED_LOCALES, configurei18n, type SupportedLocale, } from "../lib/i18n";
|
|
97
|
-
export { STORAGE_KEYS, TOKEN_QUERY_KEY, type TokenData, ensureValidToken, login, logout, resolveReturnPath, toCodedAppFilePath, } from "../lib/auth";
|
|
97
|
+
export { STORAGE_KEYS, TOKEN_QUERY_KEY, type TokenData, ensureValidToken, getStoredIdToken, getTokenQueryKey, login, logout, resolveReturnPath, toCodedAppFilePath, } from "../lib/auth";
|
|
98
98
|
export { GroupMembershipGuard, type GroupMembershipGuardProps, } from "../registry/shell/group-membership-guard";
|
|
99
99
|
export { useGroupId, type UseGroupIdOptions, type UseGroupIdResult, } from "../registry/shell/use-group-id";
|
|
100
100
|
export { useGroupMembers, type UseGroupMembersOptions, type UseGroupMembersResult, } from "../registry/shell/use-group-members";
|
package/dist/entries/index.js
CHANGED
|
@@ -16,7 +16,7 @@ import { ShellLogin } from "../registry/shell/shell-login.js";
|
|
|
16
16
|
import { ShellLayout } from "../registry/shell/shell-layout.js";
|
|
17
17
|
import { ShellSidebar } from "../registry/shell/shell-sidebar.js";
|
|
18
18
|
import { ShellUserProvider, useUser } from "../registry/shell/shell-user-provider.js";
|
|
19
|
-
import { STORAGE_KEYS, TOKEN_QUERY_KEY, ensureValidToken, login, logout, resolveReturnPath, toCodedAppFilePath } from "../lib/auth.js";
|
|
19
|
+
import { STORAGE_KEYS, TOKEN_QUERY_KEY, ensureValidToken, getStoredIdToken, getTokenQueryKey, login, logout, resolveReturnPath, toCodedAppFilePath } from "../lib/auth.js";
|
|
20
20
|
import { GroupMembershipGuard } from "../registry/shell/group-membership-guard.js";
|
|
21
21
|
import { useGroupId } from "../registry/shell/use-group-id.js";
|
|
22
22
|
import { useGroupMembers } from "../registry/shell/use-group-members.js";
|
|
@@ -142,4 +142,4 @@ export * from "../registry/ai-chat/tools/data-fabric-line/index.js";
|
|
|
142
142
|
export * from "../registry/ai-chat/tools/data-fabric-multi-line/index.js";
|
|
143
143
|
export * from "../registry/ai-chat/tools/data-fabric-table/index.js";
|
|
144
144
|
export * from "../registry/ai-chat/tools/data-fabric/index.js";
|
|
145
|
-
export { AiChat, AiChatEmptyState, ApolloShell, AuthContext, AutopilotGradientIcon, BaselineCompare, CASE_EVALUATION_EVALUATOR_ID, CASE_EVALUATION_OUTPUT_RENDERER, CaseEvaluationDetailsSchema, CaseEvaluationOutputResult, CaseEvaluationOutputSchema, CheckboxField, EvaluationPairStatus, ExpandedAgents, ExpandedAgentsView, ExpandedRunTests, ExpandedRunTestsView, FeatureFlagContext, FeatureFlagGuard, FeatureFlagProvider, FieldError as FormFieldError, GENERIC_RENDERER, GroupMembershipGuard, IXP_EXTRACTION_EVALUATOR_ID, IXP_OUTPUT_RENDERER, IxpDetailsSchema, IxpDocStatus, IxpOutputResult, IxpOutputSchema, IxpVerdict, JSON_SIMILARITY_EVALUATOR_ID, JobRole, LLM_JUDGE_EVALUATOR_ID, LocaleProvider, MembershipDenied, NoDataMessage, ProcessOutputView, ProtectedFeatureRoute, RadioGroupField, Role, RunDetails, RunDetailsView, RunResultStatus, RunStatus, STALE_TIME_MS, STORAGE_KEYS, SUPPORTED_LOCALES, SaveAsTestButton, SelectField, ShellAuthProvider, ShellLayout, ShellLogin, ShellSidebar, ShellUserProvider, SolutionTestActionError, SolutionTestStatus, SolutionTests, SolutionTestsProvider, SolutionTestsView, SubmitButton, SummaryVerdict, SwitchField, TOKEN_QUERY_KEY, TextField, TextareaField, ThemeProvider, VerifyingMembership, VersionDeltaGlyph, addVertexTranslations, assertDateOrString, assertString, cn, configurei18n, createAgentHubConnection, createConversationalAgentConnection, createProteusProvider, ensureValidToken, genericRenderer, login, logout, makeProcessOutputRenderer, makeRenderer, resolveEvaluatorRenderer, resolveProcessOutputRenderer, resolveReturnPath, toCodedAppFilePath, useAccessToken, useAdoptJob, useAppForm, useAuth, useBaselineJobs, useCreateTest, useDataTable, useDeleteTest, useEntityColumns, useEntityDataTable, useFeatureFlag, useFeatureFlagProvider, useFieldContext, useForceStopBatch, useForceStopRun, useFormContext, useGroupId, useGroupMembers, useIsGroupMember, useIsMobile, useJobExpectedOutput, useRemoveJobBaseline, useResultAttachment, useRunResults, useRunTests, useSolutionTestBatchRuns, useSolutionTestRuns, useSolutionTests, useSolutionTestsConfig, useSolutionTestsContext, useTheme, useToggleTestActive, useTranslatedErrors, useUpdateBaseline, useUser, versionDelta, withForm };
|
|
145
|
+
export { AiChat, AiChatEmptyState, ApolloShell, AuthContext, AutopilotGradientIcon, BaselineCompare, CASE_EVALUATION_EVALUATOR_ID, CASE_EVALUATION_OUTPUT_RENDERER, CaseEvaluationDetailsSchema, CaseEvaluationOutputResult, CaseEvaluationOutputSchema, CheckboxField, EvaluationPairStatus, ExpandedAgents, ExpandedAgentsView, ExpandedRunTests, ExpandedRunTestsView, FeatureFlagContext, FeatureFlagGuard, FeatureFlagProvider, FieldError as FormFieldError, GENERIC_RENDERER, GroupMembershipGuard, IXP_EXTRACTION_EVALUATOR_ID, IXP_OUTPUT_RENDERER, IxpDetailsSchema, IxpDocStatus, IxpOutputResult, IxpOutputSchema, IxpVerdict, JSON_SIMILARITY_EVALUATOR_ID, JobRole, LLM_JUDGE_EVALUATOR_ID, LocaleProvider, MembershipDenied, NoDataMessage, ProcessOutputView, ProtectedFeatureRoute, RadioGroupField, Role, RunDetails, RunDetailsView, RunResultStatus, RunStatus, STALE_TIME_MS, STORAGE_KEYS, SUPPORTED_LOCALES, SaveAsTestButton, SelectField, ShellAuthProvider, ShellLayout, ShellLogin, ShellSidebar, ShellUserProvider, SolutionTestActionError, SolutionTestStatus, SolutionTests, SolutionTestsProvider, SolutionTestsView, SubmitButton, SummaryVerdict, SwitchField, TOKEN_QUERY_KEY, TextField, TextareaField, ThemeProvider, VerifyingMembership, VersionDeltaGlyph, addVertexTranslations, assertDateOrString, assertString, cn, configurei18n, createAgentHubConnection, createConversationalAgentConnection, createProteusProvider, ensureValidToken, genericRenderer, getStoredIdToken, getTokenQueryKey, login, logout, makeProcessOutputRenderer, makeRenderer, resolveEvaluatorRenderer, resolveProcessOutputRenderer, resolveReturnPath, toCodedAppFilePath, useAccessToken, useAdoptJob, useAppForm, useAuth, useBaselineJobs, useCreateTest, useDataTable, useDeleteTest, useEntityColumns, useEntityDataTable, useFeatureFlag, useFeatureFlagProvider, useFieldContext, useForceStopBatch, useForceStopRun, useFormContext, useGroupId, useGroupMembers, useIsGroupMember, useIsMobile, useJobExpectedOutput, useRemoveJobBaseline, useResultAttachment, useRunResults, useRunTests, useSolutionTestBatchRuns, useSolutionTestRuns, useSolutionTests, useSolutionTestsConfig, useSolutionTestsContext, useTheme, useToggleTestActive, useTranslatedErrors, useUpdateBaseline, useUser, versionDelta, withForm };
|
package/dist/lib/auth.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare const STORAGE_KEYS: {
|
|
|
5
5
|
readonly TOKEN: "uipath_token";
|
|
6
6
|
readonly CODE_VERIFIER: "uipath_code_verifier";
|
|
7
7
|
readonly STATE: "uipath_state";
|
|
8
|
+
readonly REQUESTED_SCOPE: "uipath_requested_scope";
|
|
8
9
|
readonly AUTH_RETURN_TO: "auth_return_to";
|
|
9
10
|
readonly LOGOUT_RETURN_TO: "logout_return_to";
|
|
10
11
|
};
|
|
@@ -19,7 +20,9 @@ declare const TokenDataSchema: z.ZodObject<{
|
|
|
19
20
|
expiresAt: z.ZodNumber;
|
|
20
21
|
}, z.core.$strip>;
|
|
21
22
|
export type TokenData = z.infer<typeof TokenDataSchema>;
|
|
22
|
-
export declare const
|
|
23
|
+
export declare const getTokenQueryKey: (clientId: string, scope: string) => readonly ["auth", "token", string, string];
|
|
24
|
+
export declare const getStoredIdToken: (clientId: string, scope: string) => string | null;
|
|
25
|
+
export declare const ensureValidToken: (clientId: string, scope: string, baseUrl: string, redirectPath?: string) => Promise<string | null>;
|
|
23
26
|
export declare const login: (clientId: string, scope: string, baseUrl: string, redirectPath?: string) => Promise<void>;
|
|
24
|
-
export declare const logout: (queryClient: ReturnType<typeof useQueryClient
|
|
27
|
+
export declare const logout: (queryClient: ReturnType<typeof useQueryClient>, clientId: string) => void;
|
|
25
28
|
export {};
|
package/dist/lib/auth.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { jwtDecode } from "jwt-decode";
|
|
1
2
|
import pkce_challenge from "pkce-challenge";
|
|
2
3
|
import { toast } from "sonner";
|
|
3
4
|
import { z } from "zod";
|
|
@@ -15,6 +16,7 @@ const STORAGE_KEYS = {
|
|
|
15
16
|
TOKEN: "uipath_token",
|
|
16
17
|
CODE_VERIFIER: "uipath_code_verifier",
|
|
17
18
|
STATE: "uipath_state",
|
|
19
|
+
REQUESTED_SCOPE: "uipath_requested_scope",
|
|
18
20
|
AUTH_RETURN_TO: "auth_return_to",
|
|
19
21
|
LOGOUT_RETURN_TO: "logout_return_to"
|
|
20
22
|
};
|
|
@@ -56,11 +58,35 @@ const shouldRefreshToken = (tokenData)=>{
|
|
|
56
58
|
const timeUntilExpiry = tokenData.expiresAt - Date.now();
|
|
57
59
|
return timeUntilExpiry < REFRESH_THRESHOLD_MS;
|
|
58
60
|
};
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
+
const normalizeScope = (scope)=>[
|
|
62
|
+
...new Set(scope.split(/\s+/).filter(Boolean))
|
|
63
|
+
].toSorted().join(" ");
|
|
64
|
+
const getTokenStorageKey = (clientId, scope)=>`${STORAGE_KEYS.TOKEN}:${clientId}:${normalizeScope(scope)}`;
|
|
65
|
+
const getTokenQueryKey = (clientId, scope)=>[
|
|
66
|
+
...TOKEN_QUERY_KEY,
|
|
67
|
+
clientId,
|
|
68
|
+
normalizeScope(scope)
|
|
69
|
+
];
|
|
70
|
+
const readTokenData = (storageKey)=>{
|
|
71
|
+
try {
|
|
72
|
+
const { data, success } = TokenDataSchema.safeParse(JSON.parse(localStorage.getItem(storageKey) ?? "null"));
|
|
73
|
+
return success ? data : null;
|
|
74
|
+
} catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const getStoredIdToken = (clientId, scope)=>readTokenData(getTokenStorageKey(clientId, scope))?.id_token ?? null;
|
|
79
|
+
const saveTokenData = (storageKey, tokenData)=>{
|
|
80
|
+
localStorage.setItem(storageKey, JSON.stringify(tokenData));
|
|
61
81
|
};
|
|
62
|
-
const clearTokenData = ()=>{
|
|
63
|
-
localStorage.removeItem(
|
|
82
|
+
const clearTokenData = (storageKey)=>{
|
|
83
|
+
localStorage.removeItem(storageKey);
|
|
84
|
+
};
|
|
85
|
+
const clearPendingLogin = ()=>{
|
|
86
|
+
sessionStorage.removeItem(STORAGE_KEYS.CODE_VERIFIER);
|
|
87
|
+
sessionStorage.removeItem(STORAGE_KEYS.STATE);
|
|
88
|
+
sessionStorage.removeItem(STORAGE_KEYS.REQUESTED_SCOPE);
|
|
89
|
+
sessionStorage.removeItem(STORAGE_KEYS.AUTH_RETURN_TO);
|
|
64
90
|
};
|
|
65
91
|
const fetchTokenData = async (baseUrl, body)=>{
|
|
66
92
|
const response = await fetch(getTokenEndpoint(baseUrl), {
|
|
@@ -88,14 +114,14 @@ const refreshAccessToken = (refreshToken, clientId, baseUrl)=>{
|
|
|
88
114
|
});
|
|
89
115
|
return fetchTokenData(baseUrl, body);
|
|
90
116
|
};
|
|
91
|
-
const refreshTokenIfNeeded = async (tokenData, clientId, baseUrl)=>{
|
|
117
|
+
const refreshTokenIfNeeded = async (tokenData, clientId, baseUrl, storageKey)=>{
|
|
92
118
|
if (!tokenData.refresh_token) return null;
|
|
93
119
|
try {
|
|
94
120
|
const newTokenData = await refreshAccessToken(tokenData.refresh_token, clientId, baseUrl);
|
|
95
|
-
saveTokenData(newTokenData);
|
|
121
|
+
saveTokenData(storageKey, newTokenData);
|
|
96
122
|
return newTokenData.access_token;
|
|
97
123
|
} catch {
|
|
98
|
-
clearTokenData();
|
|
124
|
+
clearTokenData(storageKey);
|
|
99
125
|
return null;
|
|
100
126
|
}
|
|
101
127
|
};
|
|
@@ -109,59 +135,50 @@ const exchangeCodeForToken = (code, codeVerifier, clientId, baseUrl, redirectPat
|
|
|
109
135
|
});
|
|
110
136
|
return fetchTokenData(baseUrl, body);
|
|
111
137
|
};
|
|
112
|
-
const handleOAuthCallback = async (clientId, baseUrl, redirectPath)=>{
|
|
138
|
+
const handleOAuthCallback = async (clientId, scope, baseUrl, redirectPath)=>{
|
|
113
139
|
const params = new URLSearchParams(window.location.search);
|
|
114
140
|
const code = params.get("code");
|
|
115
141
|
const state = params.get("state");
|
|
116
142
|
const error = params.get("error");
|
|
117
|
-
if (
|
|
118
|
-
if (!code || !state) return;
|
|
143
|
+
if (!state || !code && !error) return;
|
|
119
144
|
const storedState = sessionStorage.getItem(STORAGE_KEYS.STATE);
|
|
120
|
-
if (state !== storedState) throw new Error("State mismatch");
|
|
121
145
|
const codeVerifier = sessionStorage.getItem(STORAGE_KEYS.CODE_VERIFIER);
|
|
122
|
-
|
|
146
|
+
const requestedScope = sessionStorage.getItem(STORAGE_KEYS.REQUESTED_SCOPE);
|
|
147
|
+
const returnTo = sessionStorage.getItem(STORAGE_KEYS.AUTH_RETURN_TO) ?? window.location.pathname;
|
|
148
|
+
clearPendingLogin();
|
|
123
149
|
try {
|
|
150
|
+
if (null !== error || null === code) throw new Error(`OAuth error: ${error ?? "no code returned"}`);
|
|
151
|
+
if (state !== storedState) throw new Error("State mismatch");
|
|
152
|
+
if (!codeVerifier) throw new Error("Code verifier not found");
|
|
153
|
+
const loginUsedCurrentScope = null !== requestedScope && normalizeScope(requestedScope) === normalizeScope(scope);
|
|
154
|
+
if (!loginUsedCurrentScope) return void toast.info("Your sign-in settings changed. Please sign in again.");
|
|
124
155
|
const tokenData = await exchangeCodeForToken(code, codeVerifier, clientId, baseUrl, redirectPath);
|
|
125
|
-
|
|
126
|
-
sessionStorage.removeItem(STORAGE_KEYS.STATE);
|
|
127
|
-
saveTokenData(tokenData);
|
|
128
|
-
const returnTo = sessionStorage.getItem(STORAGE_KEYS.AUTH_RETURN_TO);
|
|
129
|
-
sessionStorage.removeItem(STORAGE_KEYS.AUTH_RETURN_TO);
|
|
130
|
-
const targetPath = returnTo ?? window.location.pathname;
|
|
131
|
-
window.history.replaceState({}, document.title, targetPath);
|
|
156
|
+
saveTokenData(getTokenStorageKey(clientId, scope), tokenData);
|
|
132
157
|
} catch (authError) {
|
|
133
|
-
clearTokenData();
|
|
134
|
-
sessionStorage.removeItem(STORAGE_KEYS.AUTH_RETURN_TO);
|
|
135
158
|
const message = authError instanceof Error ? authError.message : "Unknown error";
|
|
136
159
|
toast.error(`Authentication failed: ${message}`);
|
|
137
|
-
|
|
160
|
+
} finally{
|
|
161
|
+
window.history.replaceState({}, document.title, returnTo);
|
|
138
162
|
}
|
|
139
163
|
};
|
|
140
|
-
const ensureValidToken = async (
|
|
141
|
-
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
await handleOAuthCallback(clientId, baseUrl, redirectPath);
|
|
145
|
-
} catch {
|
|
146
|
-
queryClient.resetQueries({
|
|
147
|
-
queryKey: TOKEN_QUERY_KEY
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
const tokenDataStr = localStorage.getItem(STORAGE_KEYS.TOKEN);
|
|
164
|
+
const ensureValidToken = async (clientId, scope, baseUrl, redirectPath)=>{
|
|
165
|
+
await handleOAuthCallback(clientId, scope, baseUrl, redirectPath);
|
|
166
|
+
const storageKey = getTokenStorageKey(clientId, scope);
|
|
167
|
+
const tokenDataStr = localStorage.getItem(storageKey);
|
|
151
168
|
if (!tokenDataStr) return null;
|
|
152
169
|
let parsed;
|
|
153
170
|
try {
|
|
154
171
|
parsed = JSON.parse(tokenDataStr);
|
|
155
172
|
} catch {
|
|
156
|
-
clearTokenData();
|
|
173
|
+
clearTokenData(storageKey);
|
|
157
174
|
return null;
|
|
158
175
|
}
|
|
159
176
|
const { data: tokenData, success } = TokenDataSchema.safeParse(parsed);
|
|
160
177
|
if (!success) {
|
|
161
|
-
clearTokenData();
|
|
178
|
+
clearTokenData(storageKey);
|
|
162
179
|
return null;
|
|
163
180
|
}
|
|
164
|
-
if (isTokenExpired(tokenData) || shouldRefreshToken(tokenData)) return refreshTokenIfNeeded(tokenData, clientId, baseUrl);
|
|
181
|
+
if (isTokenExpired(tokenData) || shouldRefreshToken(tokenData)) return refreshTokenIfNeeded(tokenData, clientId, baseUrl, storageKey);
|
|
165
182
|
return tokenData.access_token;
|
|
166
183
|
};
|
|
167
184
|
const login = async (clientId, scope, baseUrl, redirectPath)=>{
|
|
@@ -169,6 +186,7 @@ const login = async (clientId, scope, baseUrl, redirectPath)=>{
|
|
|
169
186
|
const state = generateRandomString(32);
|
|
170
187
|
sessionStorage.setItem(STORAGE_KEYS.CODE_VERIFIER, pkce.code_verifier);
|
|
171
188
|
sessionStorage.setItem(STORAGE_KEYS.STATE, state);
|
|
189
|
+
sessionStorage.setItem(STORAGE_KEYS.REQUESTED_SCOPE, scope);
|
|
172
190
|
if (redirectPath && window.location.pathname !== redirectPath) sessionStorage.setItem(STORAGE_KEYS.AUTH_RETURN_TO, window.location.pathname);
|
|
173
191
|
const params = new URLSearchParams({
|
|
174
192
|
client_id: clientId,
|
|
@@ -181,13 +199,28 @@ const login = async (clientId, scope, baseUrl, redirectPath)=>{
|
|
|
181
199
|
});
|
|
182
200
|
window.location.href = `${getAuthorizationEndpoint(baseUrl)}?${params.toString()}`;
|
|
183
201
|
};
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
202
|
+
const isUnscopedSessionOf = (clientId)=>{
|
|
203
|
+
const tokenData = readTokenData(STORAGE_KEYS.TOKEN);
|
|
204
|
+
if (null === tokenData) return true;
|
|
205
|
+
try {
|
|
206
|
+
const { aud } = jwtDecode(tokenData.id_token);
|
|
207
|
+
return Array.isArray(aud) ? aud.includes(clientId) : aud === clientId;
|
|
208
|
+
} catch {
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
const logout = (queryClient, clientId)=>{
|
|
213
|
+
const clientPrefix = `${STORAGE_KEYS.TOKEN}:${clientId}:`;
|
|
214
|
+
const sessionKeys = Array.from({
|
|
215
|
+
length: localStorage.length
|
|
216
|
+
}, (_, index)=>localStorage.key(index)).filter((key)=>key === STORAGE_KEYS.TOKEN ? isUnscopedSessionOf(clientId) : key?.startsWith(clientPrefix) === true);
|
|
217
|
+
for (const key of sessionKeys)clearTokenData(key);
|
|
218
|
+
clearPendingLogin();
|
|
189
219
|
queryClient.resetQueries({
|
|
190
|
-
queryKey:
|
|
220
|
+
queryKey: [
|
|
221
|
+
...TOKEN_QUERY_KEY,
|
|
222
|
+
clientId
|
|
223
|
+
]
|
|
191
224
|
});
|
|
192
225
|
};
|
|
193
|
-
export { STORAGE_KEYS, TOKEN_QUERY_KEY, ensureValidToken, login, logout, resolveReturnPath, toCodedAppFilePath };
|
|
226
|
+
export { STORAGE_KEYS, TOKEN_QUERY_KEY, ensureValidToken, getStoredIdToken, getTokenQueryKey, login, logout, resolveReturnPath, toCodedAppFilePath };
|
|
@@ -18,8 +18,9 @@ interface UseAccessTokenProps {
|
|
|
18
18
|
clientId: string;
|
|
19
19
|
baseUrl: string;
|
|
20
20
|
redirectPath?: string;
|
|
21
|
+
scope: string;
|
|
21
22
|
}
|
|
22
|
-
export declare const useAccessToken: ({ clientId, baseUrl, redirectPath, }: UseAccessTokenProps) => {
|
|
23
|
+
export declare const useAccessToken: ({ clientId, baseUrl, redirectPath, scope, }: UseAccessTokenProps) => {
|
|
23
24
|
accessToken: string | null;
|
|
24
25
|
isLoading: boolean;
|
|
25
26
|
};
|
|
@@ -4,7 +4,7 @@ import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
|
4
4
|
import { jwtDecode } from "jwt-decode";
|
|
5
5
|
import { createContext, useContext } from "react";
|
|
6
6
|
import { z } from "zod";
|
|
7
|
-
import {
|
|
7
|
+
import { ensureValidToken, getTokenQueryKey, login, logout } from "../../lib/auth.js";
|
|
8
8
|
const JwtPayloadSchema = z.object({
|
|
9
9
|
email: z.email(),
|
|
10
10
|
first_name: z.string(),
|
|
@@ -36,11 +36,10 @@ const useAuth = ()=>{
|
|
|
36
36
|
const context = useContext(AuthContext);
|
|
37
37
|
return context ?? noAuthDefaults;
|
|
38
38
|
};
|
|
39
|
-
const useAccessToken = ({ clientId, baseUrl, redirectPath })=>{
|
|
40
|
-
const queryClient = useQueryClient();
|
|
39
|
+
const useAccessToken = ({ clientId, baseUrl, redirectPath, scope })=>{
|
|
41
40
|
const { data: token, isLoading } = useQuery({
|
|
42
|
-
queryKey:
|
|
43
|
-
queryFn: ()=>ensureValidToken(
|
|
41
|
+
queryKey: getTokenQueryKey(clientId, scope),
|
|
42
|
+
queryFn: ()=>ensureValidToken(clientId, scope, baseUrl, redirectPath),
|
|
44
43
|
refetchInterval: 60000,
|
|
45
44
|
enabled: "u" > typeof window
|
|
46
45
|
});
|
|
@@ -54,7 +53,8 @@ const ShellAuthProvider = ({ children, clientId, scope, baseUrl, redirectPath })
|
|
|
54
53
|
const { accessToken, isLoading } = useAccessToken({
|
|
55
54
|
clientId,
|
|
56
55
|
baseUrl,
|
|
57
|
-
redirectPath
|
|
56
|
+
redirectPath,
|
|
57
|
+
scope
|
|
58
58
|
});
|
|
59
59
|
const user = accessToken ? decodeJWT(accessToken) : null;
|
|
60
60
|
const isAuthenticated = null != accessToken;
|
|
@@ -63,7 +63,7 @@ const ShellAuthProvider = ({ children, clientId, scope, baseUrl, redirectPath })
|
|
|
63
63
|
isAuthenticated,
|
|
64
64
|
isLoading,
|
|
65
65
|
login: ()=>login(clientId, scope, baseUrl, redirectPath),
|
|
66
|
-
logout: ()=>logout(queryClient),
|
|
66
|
+
logout: ()=>logout(queryClient, clientId),
|
|
67
67
|
accessToken
|
|
68
68
|
};
|
|
69
69
|
return /*#__PURE__*/ jsx(AuthContext.Provider, {
|