@vc-shell/framework 1.0.79 → 1.0.80
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 +4 -0
- package/core/composables/useUser/index.ts +30 -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,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,8 @@ 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
|
-
await loadUser();
|
|
114
127
|
}
|
|
128
|
+
await loadUser();
|
|
115
129
|
return { succeeded: true };
|
|
116
130
|
}
|
|
117
131
|
|
|
@@ -133,17 +147,19 @@ export function useUser(): IUseUser {
|
|
|
133
147
|
const token = await getAccessToken();
|
|
134
148
|
if (token) {
|
|
135
149
|
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
150
|
}
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
loading.value = true;
|
|
154
|
+
user.value = await securityClient.getCurrentUser();
|
|
155
|
+
console.log("[useUser]: an user details has been loaded", user.value);
|
|
156
|
+
} catch (e) {
|
|
157
|
+
console.dir(e);
|
|
158
|
+
throw e;
|
|
159
|
+
} finally {
|
|
160
|
+
loading.value = false;
|
|
161
|
+
}
|
|
162
|
+
|
|
147
163
|
return { ...user.value } as UserDetail;
|
|
148
164
|
}
|
|
149
165
|
|
|
@@ -293,7 +309,6 @@ export function useUser(): IUseUser {
|
|
|
293
309
|
}
|
|
294
310
|
url_ = url_.replace(/[?&]$/, "");
|
|
295
311
|
isExternalSignedIn.value = true;
|
|
296
|
-
initInterceptor();
|
|
297
312
|
|
|
298
313
|
window.location.href = url_;
|
|
299
314
|
} catch (e) {
|
|
@@ -318,8 +333,6 @@ export function useUser(): IUseUser {
|
|
|
318
333
|
method: "GET",
|
|
319
334
|
headers: {},
|
|
320
335
|
});
|
|
321
|
-
|
|
322
|
-
fetchIntercept.clear();
|
|
323
336
|
} catch (e) {
|
|
324
337
|
console.error(e);
|
|
325
338
|
|
|
@@ -350,6 +363,7 @@ export function useUser(): IUseUser {
|
|
|
350
363
|
/* Intercepting requests to explicitly remove auth token when we use AzureAd authentication */
|
|
351
364
|
function initInterceptor() {
|
|
352
365
|
console.log("[@vc-shell/framework#useUser:initInterceptor]: Entry point");
|
|
366
|
+
// store external login in localStorage
|
|
353
367
|
return fetchIntercept.register({
|
|
354
368
|
request: function (_url, config) {
|
|
355
369
|
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.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,GAAG,EAAO,WAAW,EAAkD,MAAM,KAAK,CAAC;AAEtG,OAAO,EACL,UAAU,EAGV,cAAc,EAEd,cAAc,EACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAY,qBAAqB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAmB/E,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAA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