@vc-shell/framework 1.0.79 → 1.0.81
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 +8 -0
- package/core/composables/useUser/index.ts +31 -16
- package/dist/core/composables/useUser/index.d.ts.map +1 -1
- package/dist/framework.mjs +6010 -6004
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## [1.0.81](https://github.com/VirtoCommerce/vc-shell/compare/v1.0.80...v1.0.81) (2023-06-23)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
## [1.0.80](https://github.com/VirtoCommerce/vc-shell/compare/v1.0.79...v1.0.80) (2023-06-22)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
1
9
|
## [1.0.79](https://github.com/VirtoCommerce/vc-shell/compare/v1.0.78...v1.0.79) (2023-06-22)
|
|
2
10
|
|
|
3
11
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computed, Ref, ref, ComputedRef, onUnmounted, getCurrentInstance, inject } from "vue";
|
|
1
|
+
import { computed, Ref, ref, ComputedRef, onUnmounted, getCurrentInstance, inject, watch } from "vue";
|
|
2
2
|
import ClientOAuth2 from "client-oauth2";
|
|
3
3
|
import {
|
|
4
4
|
UserDetail,
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
import { AuthData, RequestPasswordResult, SignInResults } from "./../../types";
|
|
12
12
|
import * as _ from "lodash-es";
|
|
13
13
|
import fetchIntercept from "fetch-intercept";
|
|
14
|
+
import { useLocalStorage } from "@vueuse/core";
|
|
14
15
|
//The Platform Manager uses the same key to store authorization data in the
|
|
15
16
|
//local storage, so we can exchange authorization data between the Platform Manager
|
|
16
17
|
//and the user application that is hosted in the same domain as the sub application.
|
|
@@ -23,7 +24,6 @@ const authClient = new ClientOAuth2({
|
|
|
23
24
|
accessTokenUri: `/connect/token`,
|
|
24
25
|
scopes: ["offline_access"],
|
|
25
26
|
});
|
|
26
|
-
const isExternalSignedIn = ref(false);
|
|
27
27
|
const activeAuthenticationType = ref();
|
|
28
28
|
const securityClient = new SecurityClient();
|
|
29
29
|
|
|
@@ -61,6 +61,20 @@ interface IUseUser {
|
|
|
61
61
|
|
|
62
62
|
export function useUser(): IUseUser {
|
|
63
63
|
const base = inject("platformUrl");
|
|
64
|
+
const isExternalSignedIn = useLocalStorage("VC_EXTERNAL_LOGIN", false);
|
|
65
|
+
|
|
66
|
+
watch(
|
|
67
|
+
() => isExternalSignedIn,
|
|
68
|
+
(newVal) => {
|
|
69
|
+
if (newVal.value) {
|
|
70
|
+
initInterceptor();
|
|
71
|
+
} else {
|
|
72
|
+
fetchIntercept.clear();
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
{ immediate: true }
|
|
76
|
+
);
|
|
77
|
+
|
|
64
78
|
async function validateToken(userId: string, token: string): Promise<boolean> {
|
|
65
79
|
let result = false;
|
|
66
80
|
try {
|
|
@@ -110,8 +124,9 @@ export function useUser(): IUseUser {
|
|
|
110
124
|
console.log("[useUser]: an access token has been obtained successfully", authData.value);
|
|
111
125
|
|
|
112
126
|
storeAuthData(authData.value);
|
|
113
|
-
|
|
127
|
+
isExternalSignedIn.value = false;
|
|
114
128
|
}
|
|
129
|
+
await loadUser();
|
|
115
130
|
return { succeeded: true };
|
|
116
131
|
}
|
|
117
132
|
|
|
@@ -133,17 +148,19 @@ export function useUser(): IUseUser {
|
|
|
133
148
|
const token = await getAccessToken();
|
|
134
149
|
if (token) {
|
|
135
150
|
securityClient.setAuthToken(token);
|
|
136
|
-
try {
|
|
137
|
-
loading.value = true;
|
|
138
|
-
user.value = await securityClient.getCurrentUser();
|
|
139
|
-
console.log("[useUser]: an user details has been loaded", user.value);
|
|
140
|
-
} catch (e) {
|
|
141
|
-
console.dir(e);
|
|
142
|
-
throw e;
|
|
143
|
-
} finally {
|
|
144
|
-
loading.value = false;
|
|
145
|
-
}
|
|
146
151
|
}
|
|
152
|
+
|
|
153
|
+
try {
|
|
154
|
+
loading.value = true;
|
|
155
|
+
user.value = await securityClient.getCurrentUser();
|
|
156
|
+
console.log("[useUser]: an user details has been loaded", user.value);
|
|
157
|
+
} catch (e) {
|
|
158
|
+
console.dir(e);
|
|
159
|
+
throw e;
|
|
160
|
+
} finally {
|
|
161
|
+
loading.value = false;
|
|
162
|
+
}
|
|
163
|
+
|
|
147
164
|
return { ...user.value } as UserDetail;
|
|
148
165
|
}
|
|
149
166
|
|
|
@@ -293,7 +310,6 @@ export function useUser(): IUseUser {
|
|
|
293
310
|
}
|
|
294
311
|
url_ = url_.replace(/[?&]$/, "");
|
|
295
312
|
isExternalSignedIn.value = true;
|
|
296
|
-
initInterceptor();
|
|
297
313
|
|
|
298
314
|
window.location.href = url_;
|
|
299
315
|
} catch (e) {
|
|
@@ -318,8 +334,6 @@ export function useUser(): IUseUser {
|
|
|
318
334
|
method: "GET",
|
|
319
335
|
headers: {},
|
|
320
336
|
});
|
|
321
|
-
|
|
322
|
-
fetchIntercept.clear();
|
|
323
337
|
} catch (e) {
|
|
324
338
|
console.error(e);
|
|
325
339
|
|
|
@@ -350,6 +364,7 @@ export function useUser(): IUseUser {
|
|
|
350
364
|
/* Intercepting requests to explicitly remove auth token when we use AzureAd authentication */
|
|
351
365
|
function initInterceptor() {
|
|
352
366
|
console.log("[@vc-shell/framework#useUser:initInterceptor]: Entry point");
|
|
367
|
+
// store external login in localStorage
|
|
353
368
|
return fetchIntercept.register({
|
|
354
369
|
request: function (_url, config) {
|
|
355
370
|
if (isExternalSignedIn.value) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../core/composables/useUser/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,GAAG,EAAO,WAAW,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../core/composables/useUser/index.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