@autenticar-me/vue 0.14.0 → 0.16.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/dist/composables/useAtm.d.ts +2 -0
- package/dist/composables/useAtm.d.ts.map +1 -1
- package/dist/composables/useAuth.d.ts +2 -0
- package/dist/composables/useAuth.d.ts.map +1 -1
- package/dist/index.cjs +80 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +80 -19
- package/dist/index.js.map +1 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/utils/auth-polling.d.ts +6 -0
- package/dist/utils/auth-polling.d.ts.map +1 -0
- package/dist/utils/fetch-user.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -9,5 +9,7 @@ export type Atm = {
|
|
|
9
9
|
configurations: Ref<undefined | null | Configurations>;
|
|
10
10
|
isSignedIn: ComputedRef<boolean>;
|
|
11
11
|
isLoaded: Ref<boolean>;
|
|
12
|
+
onLogout: (callback: () => void) => (() => void);
|
|
13
|
+
emitLogout: () => void;
|
|
12
14
|
};
|
|
13
15
|
//# sourceMappingURL=useAtm.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAtm.d.ts","sourceRoot":"","sources":["../../src/composables/useAtm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,WAAW,EAAE,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;AACzD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAEnE,wBAAgB,MAAM,IAAI,GAAG,CAQ5B;AAED,MAAM,MAAM,GAAG,GAAG;IACd,MAAM,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC;IACvB,IAAI,EAAE,GAAG,CAAC,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC;IACnC,cAAc,EAAE,GAAG,CAAC,SAAS,GAAG,IAAI,GAAG,cAAc,CAAC,CAAC;IACvD,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IACjC,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;CAC1B,CAAA"}
|
|
1
|
+
{"version":3,"file":"useAtm.d.ts","sourceRoot":"","sources":["../../src/composables/useAtm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,WAAW,EAAE,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;AACzD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAEnE,wBAAgB,MAAM,IAAI,GAAG,CAQ5B;AAED,MAAM,MAAM,GAAG,GAAG;IACd,MAAM,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC;IACvB,IAAI,EAAE,GAAG,CAAC,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC;IACnC,cAAc,EAAE,GAAG,CAAC,SAAS,GAAG,IAAI,GAAG,cAAc,CAAC,CAAC;IACvD,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IACjC,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IACvB,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC;IACjD,UAAU,EAAE,MAAM,IAAI,CAAC;CAC1B,CAAA"}
|
|
@@ -4,5 +4,7 @@ export declare function useAuth(): {
|
|
|
4
4
|
getAccessToken: () => Promise<string | null>;
|
|
5
5
|
fetchUser: (client: import('vue').Ref<import('@autenticar-me/client-js').AtmClient>, user: import('vue').Ref) => Promise<void>;
|
|
6
6
|
logout: () => Promise<void>;
|
|
7
|
+
startAuthPolling: () => void;
|
|
8
|
+
stopAuthPolling: () => void;
|
|
7
9
|
};
|
|
8
10
|
//# sourceMappingURL=useAuth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../src/composables/useAuth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../src/composables/useAuth.ts"],"names":[],"mappings":"AAKA,wBAAgB,OAAO;;uCAG6B,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;;;kBAM7C,OAAO,CAAC,IAAI,CAAC;4BAkBT,IAAI;2BAIL,IAAI;EAanC"}
|
package/dist/index.cjs
CHANGED
|
@@ -37,21 +37,26 @@ const fetchUser = async (client, user) => {
|
|
|
37
37
|
user.value = null;
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
40
|
+
try {
|
|
41
|
+
const response = await client.value.account(accessToken).getProfile();
|
|
42
|
+
user.value = {
|
|
43
|
+
id: response.id,
|
|
44
|
+
username: response.username,
|
|
45
|
+
firstName: response.first_name,
|
|
46
|
+
lastName: response.last_name,
|
|
47
|
+
primaryEmailAddress: response.primary_email_address,
|
|
48
|
+
primaryEmailAddressId: response.primary_email_address_id,
|
|
49
|
+
profileImage: response.profile_image,
|
|
50
|
+
attributes: response.attributes.map((atribute) => ({
|
|
51
|
+
key: atribute.key,
|
|
52
|
+
mode: atribute.mode,
|
|
53
|
+
value: atribute.value
|
|
54
|
+
}))
|
|
55
|
+
};
|
|
56
|
+
} catch (error) {
|
|
57
|
+
user.value = null;
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
55
60
|
};
|
|
56
61
|
function useAtm() {
|
|
57
62
|
const ctx = vue.inject("atm");
|
|
@@ -60,13 +65,40 @@ function useAtm() {
|
|
|
60
65
|
}
|
|
61
66
|
return ctx;
|
|
62
67
|
}
|
|
68
|
+
let authPollingInterval = null;
|
|
69
|
+
const startAuthPolling = (client, user, emitLogout) => {
|
|
70
|
+
if (authPollingInterval !== null) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
authPollingInterval = window.setInterval(async () => {
|
|
74
|
+
if (user.value === null || user.value === void 0) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
await fetchUser(client, user);
|
|
79
|
+
} catch (error) {
|
|
80
|
+
stopAuthPolling();
|
|
81
|
+
user.value = null;
|
|
82
|
+
writeAccessTokenInCookie(null);
|
|
83
|
+
emitLogout();
|
|
84
|
+
}
|
|
85
|
+
}, 3e3);
|
|
86
|
+
};
|
|
87
|
+
const stopAuthPolling = () => {
|
|
88
|
+
if (authPollingInterval !== null) {
|
|
89
|
+
clearInterval(authPollingInterval);
|
|
90
|
+
authPollingInterval = null;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
63
93
|
function useAuth() {
|
|
64
|
-
const { client, user } = useAtm();
|
|
94
|
+
const { client, user, emitLogout } = useAtm();
|
|
65
95
|
const signInByAccessToken = async (accessToken) => {
|
|
66
96
|
writeAccessTokenInCookie(accessToken);
|
|
67
97
|
await fetchUser(client, user);
|
|
98
|
+
startAuthPolling(client, user, emitLogout);
|
|
68
99
|
};
|
|
69
100
|
const logout = async () => {
|
|
101
|
+
stopAuthPolling();
|
|
70
102
|
const accessToken = await getAccessToken();
|
|
71
103
|
if (accessToken == null) {
|
|
72
104
|
return;
|
|
@@ -74,13 +106,22 @@ function useAuth() {
|
|
|
74
106
|
await client.value.account(accessToken).logout();
|
|
75
107
|
user.value = null;
|
|
76
108
|
writeAccessTokenInCookie(null);
|
|
109
|
+
emitLogout();
|
|
110
|
+
};
|
|
111
|
+
const startAuthPolling$1 = () => {
|
|
112
|
+
startAuthPolling(client, user, emitLogout);
|
|
113
|
+
};
|
|
114
|
+
const stopAuthPolling$1 = () => {
|
|
115
|
+
stopAuthPolling();
|
|
77
116
|
};
|
|
78
117
|
return {
|
|
79
118
|
user,
|
|
80
119
|
signInByAccessToken,
|
|
81
120
|
getAccessToken,
|
|
82
121
|
fetchUser,
|
|
83
|
-
logout
|
|
122
|
+
logout,
|
|
123
|
+
startAuthPolling: startAuthPolling$1,
|
|
124
|
+
stopAuthPolling: stopAuthPolling$1
|
|
84
125
|
};
|
|
85
126
|
}
|
|
86
127
|
const _hoisted_1$8 = { class: "atm-overlay" };
|
|
@@ -2461,16 +2502,36 @@ const atmPlugin = {
|
|
|
2461
2502
|
const configurations = vue.ref(null);
|
|
2462
2503
|
const isSignedIn = vue.computed(() => user.value !== void 0 && user.value !== null);
|
|
2463
2504
|
const isLoaded = vue.ref(false);
|
|
2505
|
+
const logoutCallbacks = [];
|
|
2506
|
+
const onLogout = (callback) => {
|
|
2507
|
+
logoutCallbacks.push(callback);
|
|
2508
|
+
return () => {
|
|
2509
|
+
const index = logoutCallbacks.indexOf(callback);
|
|
2510
|
+
if (index > -1) {
|
|
2511
|
+
logoutCallbacks.splice(index, 1);
|
|
2512
|
+
}
|
|
2513
|
+
};
|
|
2514
|
+
};
|
|
2515
|
+
const emitLogout = () => {
|
|
2516
|
+
logoutCallbacks.forEach((callback) => callback());
|
|
2517
|
+
};
|
|
2464
2518
|
Promise.all([
|
|
2465
2519
|
fetchUser(client, user),
|
|
2466
2520
|
fetchConfigurations(client, configurations)
|
|
2467
|
-
]).then(() =>
|
|
2521
|
+
]).then(() => {
|
|
2522
|
+
isLoaded.value = true;
|
|
2523
|
+
if (user.value !== null && user.value !== void 0) {
|
|
2524
|
+
startAuthPolling(client, user, emitLogout);
|
|
2525
|
+
}
|
|
2526
|
+
});
|
|
2468
2527
|
app.provide("atm", {
|
|
2469
2528
|
client,
|
|
2470
2529
|
user,
|
|
2471
2530
|
configurations,
|
|
2472
2531
|
isSignedIn,
|
|
2473
|
-
isLoaded
|
|
2532
|
+
isLoaded,
|
|
2533
|
+
onLogout,
|
|
2534
|
+
emitLogout
|
|
2474
2535
|
});
|
|
2475
2536
|
}
|
|
2476
2537
|
};
|