@tapni/auth 0.0.94 → 0.0.96

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tapni/auth",
3
- "version": "0.0.94",
3
+ "version": "0.0.96",
4
4
  "type": "module",
5
5
  "main": "./dist/TapniAuth.umd.js",
6
6
  "module": "./dist/TapniAuth.es.js",
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 () {
@@ -134,7 +135,6 @@ export default {
134
135
 
135
136
  this.setToken(this.$storage.token);
136
137
  const refreshTokens = this.getRefreshTokens();
137
- console.log({refreshTokens});
138
138
  this.setRefreshToken(refreshTokens[0]);
139
139
  await this.getLoggedInAccounts(refreshTokens);
140
140
 
@@ -245,7 +245,7 @@ export default {
245
245
  },
246
246
  async refreshTokenAction(data) {
247
247
  return new Promise(async (resolve, reject) => {
248
- if (!this.refreshToken || this.refreshing) {
248
+ if (!data.refreshToken || this.refreshing) {
249
249
  return resolve(null);
250
250
  }
251
251
 
@@ -255,7 +255,7 @@ export default {
255
255
  id: data.id,
256
256
  refreshToken: data.refreshToken,
257
257
  refreshTokenAction: true
258
- }, this.$storage)
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
- this.setToken(response.data.token);
267
+ EventBus.$emit("setToken", response.data.token);
268
268
  EventBus.$emit("ssoEvent", { name: "setStorage", data: this.$storage });
269
269
  resolve(response.data.token);
270
- } else reject('Invalid response setToken');
270
+ }
271
271
  this.refreshing = false;
272
272
  })
273
273
  },
@@ -10,7 +10,7 @@ export default {
10
10
  setApiRootFromOptions(apiRoot) {
11
11
  apiRootFromOptions = apiRoot
12
12
  },
13
- instance(storage, refreshTokenAction = false) {
13
+ instance(storage, refreshTokenAction = null) {
14
14
 
15
15
  const appInfo = version;
16
16
  let baseURL = import.meta.env.VITE_APP_API_ROOT + '/v1/';
@@ -56,7 +56,7 @@ export default {
56
56
  // Check if access token expired
57
57
  if (decoded.exp - 30 < Math.floor(Date.now() / 1000)) {
58
58
 
59
- return AuthMixin.methods.refreshTokenAction({...decoded, refreshToken: storage.refreshTokens ? storage.refreshTokens.split(',')[0] : null })
59
+ return AuthMixin.methods.refreshTokenAction({...decoded, refreshToken: storage.refreshTokens ? storage.refreshTokens.split(',')[0] : null, storage })
60
60
  .then((token) => {
61
61
  config.headers = {
62
62
  ...config.headers,