@tapni/auth 0.0.93 → 0.0.95
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 +1172 -1175
- package/dist/TapniAuth.umd.js +3 -3
- package/package.json +1 -1
- package/src/App.vue +2 -1
- package/src/mixins/auth.mixin.js +8 -10
- package/src/services/Api.js +6 -8
package/package.json
CHANGED
package/src/App.vue
CHANGED
|
@@ -123,8 +123,9 @@ export default {
|
|
|
123
123
|
EventBus.$on('ssoEvent', this.ssoOutgoingEvent)
|
|
124
124
|
EventBus.$on('ssoLogout',(data) => this.logout(data))
|
|
125
125
|
EventBus.$on('getLoggedInAccounts',(data) => this.getLoggedInAccounts(data))
|
|
126
|
-
EventBus.$on('refreshTokenAction',(data) => this.refreshTokenAction(data))
|
|
126
|
+
EventBus.$on('refreshTokenAction',(data) => this.refreshTokenAction({...data, storage: this.$storage}))
|
|
127
127
|
EventBus.$on('switchAccount',(data) => this.switchAccount(data))
|
|
128
|
+
EventBus.$on('setToken',(data) => this.setToken(data))
|
|
128
129
|
},
|
|
129
130
|
methods: {
|
|
130
131
|
async init () {
|
package/src/mixins/auth.mixin.js
CHANGED
|
@@ -236,7 +236,7 @@ export default {
|
|
|
236
236
|
this.$storage.UserId = this.loggedInAccounts[username].id;
|
|
237
237
|
this.setLoggedInUserId(this.loggedInAccounts[username].id);
|
|
238
238
|
this.setRefreshToken(this.loggedInAccounts[username].refreshToken);
|
|
239
|
-
await this.refreshTokenAction(
|
|
239
|
+
await this.refreshTokenAction(this.loggedInAccounts[username]);
|
|
240
240
|
|
|
241
241
|
EventBus.$emit("ssoEvent", {
|
|
242
242
|
name: "switchAccount",
|
|
@@ -245,7 +245,7 @@ export default {
|
|
|
245
245
|
},
|
|
246
246
|
async refreshTokenAction(data) {
|
|
247
247
|
return new Promise(async (resolve, reject) => {
|
|
248
|
-
if (!
|
|
248
|
+
if (!data.refreshToken || this.refreshing) {
|
|
249
249
|
return resolve(null);
|
|
250
250
|
}
|
|
251
251
|
|
|
@@ -253,9 +253,9 @@ export default {
|
|
|
253
253
|
const [err, response] = await to(
|
|
254
254
|
AuthService.refreshToken({
|
|
255
255
|
id: data.id,
|
|
256
|
-
refreshToken:
|
|
257
|
-
refreshTokenAction:
|
|
258
|
-
},
|
|
256
|
+
refreshToken: data.refreshToken,
|
|
257
|
+
refreshTokenAction: true
|
|
258
|
+
}, data.storage)
|
|
259
259
|
);
|
|
260
260
|
if (err && err.response && err.response.data.error === "ACCESS_DENIED") {
|
|
261
261
|
this.logout(false);
|
|
@@ -264,10 +264,10 @@ export default {
|
|
|
264
264
|
|
|
265
265
|
// Set new access token
|
|
266
266
|
if (response && response.data) {
|
|
267
|
-
|
|
267
|
+
EventBus.$emit("setToken", response.data.token);
|
|
268
268
|
EventBus.$emit("ssoEvent", { name: "setStorage", data: this.$storage });
|
|
269
269
|
resolve(response.data.token);
|
|
270
|
-
}
|
|
270
|
+
}
|
|
271
271
|
this.refreshing = false;
|
|
272
272
|
})
|
|
273
273
|
},
|
|
@@ -422,9 +422,7 @@ export default {
|
|
|
422
422
|
if (
|
|
423
423
|
this.loggedInAccounts[username].refreshToken === this.refreshToken
|
|
424
424
|
) {
|
|
425
|
-
this.refreshTokenAction({
|
|
426
|
-
id: this.loggedInAccounts[username].id,
|
|
427
|
-
}).then(() => {
|
|
425
|
+
this.refreshTokenAction(this.loggedInAccounts[username]).then(() => {
|
|
428
426
|
this.setLoggedInUserId(this.loggedInAccounts[username].id);
|
|
429
427
|
if (this.$storage) {
|
|
430
428
|
this.$storage.username = username;
|
package/src/services/Api.js
CHANGED
|
@@ -10,7 +10,7 @@ export default {
|
|
|
10
10
|
setApiRootFromOptions(apiRoot) {
|
|
11
11
|
apiRootFromOptions = apiRoot
|
|
12
12
|
},
|
|
13
|
-
instance(storage, refreshTokenAction) {
|
|
13
|
+
instance(storage, refreshTokenAction = null) {
|
|
14
14
|
|
|
15
15
|
const appInfo = version;
|
|
16
16
|
let baseURL = import.meta.env.VITE_APP_API_ROOT + '/v1/';
|
|
@@ -28,7 +28,8 @@ export default {
|
|
|
28
28
|
}
|
|
29
29
|
})
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
// Add a request interceptor
|
|
32
|
+
apiInstance.interceptors.request.use(async function (config) {
|
|
32
33
|
|
|
33
34
|
if (['post', 'put', 'delete'].includes(config.method.toLowerCase())) {
|
|
34
35
|
config.data = {
|
|
@@ -49,13 +50,13 @@ export default {
|
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
// Check refresh token expiration before request is sent
|
|
52
|
-
if (storage && storage.token && refreshTokenAction
|
|
53
|
+
if (storage && storage.token && !refreshTokenAction) {
|
|
53
54
|
const decoded = jwtDecode(storage.token)
|
|
54
55
|
|
|
55
56
|
// Check if access token expired
|
|
56
57
|
if (decoded.exp - 30 < Math.floor(Date.now() / 1000)) {
|
|
57
58
|
|
|
58
|
-
return refreshTokenAction(decoded)
|
|
59
|
+
return refreshTokenAction({...decoded, refreshToken: storage.refreshTokens ? storage.refreshTokens.split(',')[0] : null, storage })
|
|
59
60
|
.then((token) => {
|
|
60
61
|
config.headers = {
|
|
61
62
|
...config.headers,
|
|
@@ -66,10 +67,7 @@ export default {
|
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
69
|
return config;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Add a request interceptor
|
|
72
|
-
apiInstance.interceptors.request.use(clbck);
|
|
70
|
+
});
|
|
73
71
|
|
|
74
72
|
return apiInstance;
|
|
75
73
|
}
|