@tapni/auth 0.0.64 → 0.0.65
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 +16 -5
- package/dist/TapniAuth.umd.js +6 -6
- package/package.json +1 -1
- package/src/App.vue +1 -0
- package/src/mixins/auth.mixin.js +32 -6
package/package.json
CHANGED
package/src/App.vue
CHANGED
|
@@ -124,6 +124,7 @@ export default {
|
|
|
124
124
|
EventBus.$on('ssoLogout',(data) => this.logout(data))
|
|
125
125
|
EventBus.$on('getLoggedInAccounts',(data) => this.getLoggedInAccounts(data))
|
|
126
126
|
EventBus.$on('refreshTokenAction',(data) => this.refreshTokenAction(data))
|
|
127
|
+
EventBus.$on('switchAccount',(data) => this.switchAccount(data))
|
|
127
128
|
},
|
|
128
129
|
methods: {
|
|
129
130
|
async init () {
|
package/src/mixins/auth.mixin.js
CHANGED
|
@@ -25,6 +25,7 @@ export default {
|
|
|
25
25
|
appLanguage: "en",
|
|
26
26
|
token: "",
|
|
27
27
|
refreshToken: "",
|
|
28
|
+
refreshing: "",
|
|
28
29
|
loggedInUserId: "",
|
|
29
30
|
ssoUser: {},
|
|
30
31
|
ssoCompany: {},
|
|
@@ -240,8 +241,20 @@ export default {
|
|
|
240
241
|
// await this.registerDevice();
|
|
241
242
|
// if (Capacitor.isNativePlatform()) initPushNotifications();
|
|
242
243
|
},
|
|
243
|
-
async
|
|
244
|
+
async switchAccount(username) {
|
|
245
|
+
this.$storage.username = username;
|
|
246
|
+
this.$storage.UserId = this.loggedInAccounts[username].id;
|
|
247
|
+
this.setLoggedInUserId(this.loggedInAccounts[username].id);
|
|
248
|
+
this.setRefreshToken(this.loggedInAccounts[username].refreshToken);
|
|
249
|
+
await this.refreshTokenAction({ id: this.loggedInAccounts[username].id });
|
|
244
250
|
|
|
251
|
+
EventBus.$emit("ssoEvent", {
|
|
252
|
+
name: "switchAccount",
|
|
253
|
+
data: { lang: this.appLanguage, username },
|
|
254
|
+
});
|
|
255
|
+
},
|
|
256
|
+
async refreshTokenAction(data) {
|
|
257
|
+
this.refreshing = true;
|
|
245
258
|
const [err, response] = await to(
|
|
246
259
|
AuthService.refreshToken({
|
|
247
260
|
id: data.id,
|
|
@@ -258,6 +271,7 @@ export default {
|
|
|
258
271
|
if (response && response.data) {
|
|
259
272
|
this.setToken(response.data.token);
|
|
260
273
|
} else console.error('Invalid response setToken');
|
|
274
|
+
this.refreshing = false;
|
|
261
275
|
},
|
|
262
276
|
async login(data) {
|
|
263
277
|
const [err, response] = await to(AuthService.login(data, this.$storage));
|
|
@@ -472,17 +486,29 @@ export default {
|
|
|
472
486
|
}
|
|
473
487
|
},
|
|
474
488
|
getRefreshTokens() {
|
|
475
|
-
|
|
489
|
+
if (this.$storage && this.$storage.refreshTokens) this.$storage.refreshTokens.split(',')
|
|
490
|
+
else return [];
|
|
476
491
|
},
|
|
477
492
|
setRefreshToken(token) {
|
|
493
|
+
// Get all refresh tokens
|
|
478
494
|
let refreshTokens = this.getRefreshTokens();
|
|
479
|
-
if (token && !refreshTokens.includes(token)) refreshTokens.unshift(token);
|
|
480
|
-
else refreshTokens = refreshTokens.filter((t) => t !== this.refreshToken);
|
|
481
495
|
|
|
482
|
-
|
|
483
|
-
|
|
496
|
+
// If token exists, add to the top of the list
|
|
497
|
+
// If it doesn't exist, get the list without the current one - delete refresh
|
|
498
|
+
if (token) {
|
|
499
|
+
if (!refreshTokens.includes(token)) {
|
|
500
|
+
refreshTokens.unshift(token);
|
|
501
|
+
}
|
|
502
|
+
this.refreshToken = token;
|
|
503
|
+
} else {
|
|
504
|
+
refreshTokens = refreshTokens.filter((t) => t !== this.refreshToken);
|
|
505
|
+
|
|
506
|
+
// Set the first token as the new refresh token
|
|
507
|
+
if (refreshTokens.length >= 1) this.refreshToken = refreshTokens[0];
|
|
508
|
+
}
|
|
484
509
|
|
|
485
510
|
this.$storage.refreshTokens = refreshTokens.join(",");
|
|
511
|
+
|
|
486
512
|
EventBus.$emit("ssoEvent", { name: "setRefreshToken", data: token });
|
|
487
513
|
},
|
|
488
514
|
setToken(token) {
|