@autenticar-me/vue 0.15.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.
@@ -1 +1 @@
1
- {"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../src/composables/useAuth.ts"],"names":[],"mappings":"AAMA,wBAAgB,OAAO;;uCAG6B,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;;;kBAK7C,OAAO,CAAC,IAAI,CAAC;4BAkBT,IAAI;2BAkBL,IAAI;EAgBnC"}
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
@@ -66,11 +66,36 @@ function useAtm() {
66
66
  return ctx;
67
67
  }
68
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
+ };
69
93
  function useAuth() {
70
- const { client, user, isSignedIn, emitLogout } = useAtm();
94
+ const { client, user, emitLogout } = useAtm();
71
95
  const signInByAccessToken = async (accessToken) => {
72
96
  writeAccessTokenInCookie(accessToken);
73
97
  await fetchUser(client, user);
98
+ startAuthPolling(client, user, emitLogout);
74
99
  };
75
100
  const logout = async () => {
76
101
  stopAuthPolling();
@@ -83,26 +108,11 @@ function useAuth() {
83
108
  writeAccessTokenInCookie(null);
84
109
  emitLogout();
85
110
  };
86
- const startAuthPolling = () => {
87
- if (authPollingInterval !== null) {
88
- return;
89
- }
90
- authPollingInterval = window.setInterval(async () => {
91
- if (!isSignedIn.value) {
92
- return;
93
- }
94
- try {
95
- await fetchUser(client, user);
96
- } catch (error) {
97
- await logout();
98
- }
99
- }, 3e3);
111
+ const startAuthPolling$1 = () => {
112
+ startAuthPolling(client, user, emitLogout);
100
113
  };
101
- const stopAuthPolling = () => {
102
- if (authPollingInterval !== null) {
103
- clearInterval(authPollingInterval);
104
- authPollingInterval = null;
105
- }
114
+ const stopAuthPolling$1 = () => {
115
+ stopAuthPolling();
106
116
  };
107
117
  return {
108
118
  user,
@@ -110,8 +120,8 @@ function useAuth() {
110
120
  getAccessToken,
111
121
  fetchUser,
112
122
  logout,
113
- startAuthPolling,
114
- stopAuthPolling
123
+ startAuthPolling: startAuthPolling$1,
124
+ stopAuthPolling: stopAuthPolling$1
115
125
  };
116
126
  }
117
127
  const _hoisted_1$8 = { class: "atm-overlay" };
@@ -2508,7 +2518,12 @@ const atmPlugin = {
2508
2518
  Promise.all([
2509
2519
  fetchUser(client, user),
2510
2520
  fetchConfigurations(client, configurations)
2511
- ]).then(() => isLoaded.value = true);
2521
+ ]).then(() => {
2522
+ isLoaded.value = true;
2523
+ if (user.value !== null && user.value !== void 0) {
2524
+ startAuthPolling(client, user, emitLogout);
2525
+ }
2526
+ });
2512
2527
  app.provide("atm", {
2513
2528
  client,
2514
2529
  user,