@tapni/auth 0.0.77 → 0.0.79
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/TapniAuth.es.js +21 -19
- package/dist/TapniAuth.umd.js +6 -6
- package/package.json +1 -1
- package/src/mixins/auth.mixin.js +26 -21
- package/src/services/Api.js +4 -2
package/package.json
CHANGED
package/src/mixins/auth.mixin.js
CHANGED
|
@@ -244,29 +244,34 @@ export default {
|
|
|
244
244
|
});
|
|
245
245
|
},
|
|
246
246
|
async refreshTokenAction(data) {
|
|
247
|
-
|
|
248
|
-
console.log('
|
|
249
|
-
|
|
250
|
-
|
|
247
|
+
return new Promise(async (resolve, reject) => {
|
|
248
|
+
console.log('auth-refreshTokenAction', data);
|
|
249
|
+
if (!this.refreshToken || this.refreshing) {
|
|
250
|
+
console.log('return-refreshTokenAction', this.refreshToken, this.refreshing);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
251
253
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
254
|
+
this.refreshing = true;
|
|
255
|
+
const [err, response] = await to(
|
|
256
|
+
AuthService.refreshToken({
|
|
257
|
+
id: data.id,
|
|
258
|
+
refreshToken: this.refreshToken,
|
|
259
|
+
refreshTokenAction: true
|
|
260
|
+
}, this.$storage)
|
|
261
|
+
);
|
|
262
|
+
if (err && err.response && err.response.data.error === "ACCESS_DENIED") {
|
|
263
|
+
this.logout(false);
|
|
264
|
+
return location.reload();
|
|
265
|
+
}
|
|
264
266
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
267
|
+
// Set new access token
|
|
268
|
+
if (response && response.data) {
|
|
269
|
+
this.setToken(response.data.token);
|
|
270
|
+
EventBus.$emit("ssoEvent", { name: "setStorage", data: this.$storage });
|
|
271
|
+
resolve(response.data.token);
|
|
272
|
+
} else reject('Invalid response setToken');
|
|
273
|
+
this.refreshing = false;
|
|
274
|
+
})
|
|
270
275
|
},
|
|
271
276
|
async login(data) {
|
|
272
277
|
const [err, response] = await to(AuthService.login(data, this.$storage));
|
package/src/services/Api.js
CHANGED
|
@@ -49,6 +49,8 @@ export default {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
console.log('before interceptor enter', storage, refreshTokenAction);
|
|
53
|
+
|
|
52
54
|
// Check refresh token expiration before request is sent
|
|
53
55
|
if (storage && storage.token && !refreshTokenAction) {
|
|
54
56
|
const decoded = jwtDecode(storage.token)
|
|
@@ -59,10 +61,10 @@ export default {
|
|
|
59
61
|
if (decoded.exp - 30 < Math.floor(Date.now() / 1000)) {
|
|
60
62
|
|
|
61
63
|
return AuthMixin.methods.refreshTokenAction(decoded)
|
|
62
|
-
.then(() => {
|
|
64
|
+
.then((token) => {
|
|
63
65
|
config.headers = {
|
|
64
66
|
...config.headers,
|
|
65
|
-
Authorization: `Bearer ${
|
|
67
|
+
Authorization: `Bearer ${token}`
|
|
66
68
|
}
|
|
67
69
|
return config;
|
|
68
70
|
})
|