@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.
package/dist/index.js CHANGED
@@ -64,11 +64,36 @@ function useAtm() {
64
64
  return ctx;
65
65
  }
66
66
  let authPollingInterval = null;
67
+ const startAuthPolling = (client, user, emitLogout) => {
68
+ if (authPollingInterval !== null) {
69
+ return;
70
+ }
71
+ authPollingInterval = window.setInterval(async () => {
72
+ if (user.value === null || user.value === void 0) {
73
+ return;
74
+ }
75
+ try {
76
+ await fetchUser(client, user);
77
+ } catch (error) {
78
+ stopAuthPolling();
79
+ user.value = null;
80
+ writeAccessTokenInCookie(null);
81
+ emitLogout();
82
+ }
83
+ }, 3e3);
84
+ };
85
+ const stopAuthPolling = () => {
86
+ if (authPollingInterval !== null) {
87
+ clearInterval(authPollingInterval);
88
+ authPollingInterval = null;
89
+ }
90
+ };
67
91
  function useAuth() {
68
- const { client, user, isSignedIn, emitLogout } = useAtm();
92
+ const { client, user, emitLogout } = useAtm();
69
93
  const signInByAccessToken = async (accessToken) => {
70
94
  writeAccessTokenInCookie(accessToken);
71
95
  await fetchUser(client, user);
96
+ startAuthPolling(client, user, emitLogout);
72
97
  };
73
98
  const logout = async () => {
74
99
  stopAuthPolling();
@@ -81,26 +106,11 @@ function useAuth() {
81
106
  writeAccessTokenInCookie(null);
82
107
  emitLogout();
83
108
  };
84
- const startAuthPolling = () => {
85
- if (authPollingInterval !== null) {
86
- return;
87
- }
88
- authPollingInterval = window.setInterval(async () => {
89
- if (!isSignedIn.value) {
90
- return;
91
- }
92
- try {
93
- await fetchUser(client, user);
94
- } catch (error) {
95
- await logout();
96
- }
97
- }, 3e3);
109
+ const startAuthPolling$1 = () => {
110
+ startAuthPolling(client, user, emitLogout);
98
111
  };
99
- const stopAuthPolling = () => {
100
- if (authPollingInterval !== null) {
101
- clearInterval(authPollingInterval);
102
- authPollingInterval = null;
103
- }
112
+ const stopAuthPolling$1 = () => {
113
+ stopAuthPolling();
104
114
  };
105
115
  return {
106
116
  user,
@@ -108,8 +118,8 @@ function useAuth() {
108
118
  getAccessToken,
109
119
  fetchUser,
110
120
  logout,
111
- startAuthPolling,
112
- stopAuthPolling
121
+ startAuthPolling: startAuthPolling$1,
122
+ stopAuthPolling: stopAuthPolling$1
113
123
  };
114
124
  }
115
125
  const _hoisted_1$8 = { class: "atm-overlay" };
@@ -2506,7 +2516,12 @@ const atmPlugin = {
2506
2516
  Promise.all([
2507
2517
  fetchUser(client, user),
2508
2518
  fetchConfigurations(client, configurations)
2509
- ]).then(() => isLoaded.value = true);
2519
+ ]).then(() => {
2520
+ isLoaded.value = true;
2521
+ if (user.value !== null && user.value !== void 0) {
2522
+ startAuthPolling(client, user, emitLogout);
2523
+ }
2524
+ });
2510
2525
  app.provide("atm", {
2511
2526
  client,
2512
2527
  user,