@tapni/auth 0.0.119 → 0.0.129

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.119",
3
+ "version": "0.0.129",
4
4
  "type": "module",
5
5
  "main": "./dist/TapniAuth.umd.js",
6
6
  "module": "./dist/TapniAuth.es.js",
@@ -34,7 +34,7 @@
34
34
  "@codetrix-studio/capacitor-google-auth": "^3.3.6",
35
35
  "@otplib/preset-browser": "^12.0.1",
36
36
  "@recognizebv/capacitor-plugin-msauth": "^3.5.1",
37
- "@tapni/capacitor-reactive-localstorage-vue3": "^0.0.15",
37
+ "@tapni/capacitor-reactive-localstorage-vue3": "^0.0.16",
38
38
  "@tapni/styles": "^0.0.3",
39
39
  "await-to-js": "^3.0.0",
40
40
  "axios": "^1.6.5",
package/src/App.vue CHANGED
@@ -96,8 +96,10 @@ import {EventBus} from "./store/event-bus.js";
96
96
  import AuthMixin from "@/mixins/auth.mixin.js";
97
97
  import Language from "@/components/Language.vue";
98
98
  import ReactiveStorage from '@tapni/capacitor-reactive-localstorage-vue3'
99
+ import store from './store/auth.js';
99
100
 
100
101
  export default {
102
+ store,
101
103
  name: 'TapniAuth',
102
104
  mixins: [ReactiveStorage, AuthMixin],
103
105
  data () {
@@ -150,7 +152,7 @@ export default {
150
152
  async mounted() {
151
153
  console.log('eey');
152
154
  this.applyBgStyle()
153
- this.$store.commit('setView', this.viewProp);
155
+ this.setView(this.viewProp);
154
156
 
155
157
  EventBus.$on('ssoEvent', this.ssoOutgoingEvent)
156
158
  EventBus.$on('ssoLogout',(data) => this.logout(data.refreshToken))
@@ -164,7 +166,7 @@ export default {
164
166
  console.log('initt');
165
167
 
166
168
  // Set $storage into vuex $storex
167
- this.$store.commit('setStorage', this.storage);
169
+ this.setStorage(this.$storage);
168
170
 
169
171
  // Make sure the function is called just once
170
172
  if (this.isSetup) return;
@@ -199,7 +201,7 @@ export default {
199
201
  display () {
200
202
  this.applyBgStyle()
201
203
  },
202
- 'storageReady.value' (nv) {
204
+ '$storageReady.value' (nv) {
203
205
  if (nv) {
204
206
  // Initialize Library after all event listeners & storage are set
205
207
  this.$nextTick(() => {
@@ -212,7 +214,7 @@ export default {
212
214
  clearInterval(this.storeInterval);
213
215
  this.storeInterval = setTimeout(() => {
214
216
  Object.keys(nv).forEach(key => {
215
- this.storage[key] = nv[key];
217
+ this.$storage[key] = nv[key];
216
218
  });
217
219
  }, 250)
218
220
  },
package/src/install.js CHANGED
@@ -1,11 +1,14 @@
1
1
  import App from "./App.vue";
2
- import AuthMixin from './mixins/auth.mixin.js'
2
+ import auth from './store/auth.js';
3
3
 
4
4
  // Export the component by default
5
5
  export default {
6
- TapniAuth: App,
7
- AuthMixin: AuthMixin,
8
- install: (app, options) => {
6
+ install: (app, rootStore) => {
7
+ // Register the component
9
8
  app.component('TapniAuth', App);
9
+
10
+ if(!rootStore.hasModule('auth')) {
11
+ rootStore.registerModule('auth', auth);
12
+ }
10
13
  }
11
14
  };
@@ -1,4 +1,5 @@
1
- import { mapState, mapActions, mapGetters } from 'vuex';
1
+ import { createNamespacedHelpers } from 'vuex';
2
+ const { mapState, mapActions, mapGetters } = createNamespacedHelpers('auth');
2
3
  import GlobalMixin from './global.mixin'
3
4
 
4
5
  export default {
@@ -32,6 +33,8 @@ export default {
32
33
  'setRefreshToken',
33
34
  'unsetRefreshToken',
34
35
  'setToken',
36
+ 'setView',
37
+ 'setStorage',
35
38
  'setUserID',
36
39
  'updateLang',
37
40
  'login',
@@ -50,16 +53,20 @@ export default {
50
53
  'getLoggedInAccounts',
51
54
  'loginUsingQR',
52
55
  'getAccountSettings',
56
+ 'setRedirectUri',
57
+ 'setDisplay',
58
+ 'setState',
59
+ 'setResponseType',
53
60
  ])
54
61
  },
55
62
  watch: {
56
63
  "$route.query": {
57
64
  handler: function handler() {
58
- if (this.$route.query.redirect_uri) this.$store.dispatch('setRedirectUri', this.$route.query.redirect_uri);
59
- if (this.$route.query.display) this.$store.dispatch('setDisplay', this.$route.query.display);
60
- if (this.$route.query.state) this.$store.dispatch('setState', this.$route.query.state)
61
- if (this.$route.query.response_type) this.$store.dispatch('setResponseType', this.$route.query.response_type);
62
- if (this.$route.query.realm && this.$storage) this.$store.dispatch('setRealm', this.$route.query.realm);
65
+ if (this.$route.query.redirect_uri) this.setRedirectUri(this.$route.query.redirect_uri);
66
+ if (this.$route.query.display) this.setDisplay(this.$route.query.display);
67
+ if (this.$route.query.state) this.setState(this.$route.query.state)
68
+ if (this.$route.query.response_type) this.setResponseType(this.$route.query.response_type);
69
+ if (this.$route.query.realm && this.$storage) this.setRealm(this.$route.query.realm);
63
70
  },
64
71
  deep: true,
65
72
  },
@@ -3,19 +3,18 @@ import { jwtDecode } from "jwt-decode";
3
3
  import { version } from "../../package.json"
4
4
  import store from '../store/store.js';
5
5
 
6
-
7
6
  export default (refreshTokenAction = null) => {
8
7
  const appInfo = version;
9
8
  let baseURL = import.meta.env.VITE_APP_API_ROOT + '/v1/';
10
9
 
11
- if (store.getters.apiRoot) {
12
- baseURL = store.getters.apiRoot;
10
+ if (store.getters['auth/apiRoot']) {
11
+ baseURL = store.getters['auth/apiRoot'];
13
12
  }
14
13
 
15
14
  let apiInstance = axios.create({
16
15
  baseURL,
17
16
  headers: {
18
- Authorization: `Bearer ${store.getters.accessToken}`,
17
+ Authorization: `Bearer ${store.getters['auth/accessToken']}`,
19
18
  "X-Client-Name": "sso-" + appInfo.platform,
20
19
  "X-Client-Version": appInfo.version
21
20
  }
@@ -27,28 +26,28 @@ export default (refreshTokenAction = null) => {
27
26
  if (['post', 'put', 'delete'].includes(config.method.toLowerCase())) {
28
27
  config.data = {
29
28
  ...config.data,
30
- lang: store.getters.appLanguage,
31
- realm: store.getters.appRealm || 'app'
29
+ lang: store.getters['auth/appLanguage'],
30
+ realm: store.getters['auth/appRealm'] || 'app'
32
31
  }
33
32
  } else if (config.method.toLowerCase() === 'get') {
34
33
  config.params = {
35
34
  ...config.params,
36
- lang: store.getters.appLanguage,
37
- realm: store.getters.appRealm || 'app'
35
+ lang: store.getters['auth/appLanguage'],
36
+ realm: store.getters['auth/appRealm'] || 'app'
38
37
  }
39
38
  }
40
39
 
41
40
  // Check refresh token expiration before request is sent
42
- if (store.getters.accessToken && !refreshTokenAction) {
43
- const decoded = jwtDecode(store.getters.accessToken)
41
+ if (store.getters['auth/accessToken'] && !refreshTokenAction) {
42
+ const decoded = jwtDecode(store.getters['auth/accessToken'])
44
43
 
45
44
  // Check if access token expired
46
45
  if (decoded.exp - 30 < Math.floor(Date.now() / 1000)) {
47
- return store.dispatch('refreshTokenAction', decoded)
46
+ return store.dispatch('auth/refreshTokenAction', decoded)
48
47
  .then(() => {
49
48
  config.headers = {
50
49
  ...config.headers,
51
- Authorization: `Bearer ${store.getters.accessToken}`
50
+ Authorization: `Bearer ${store.getters['auth/accessToken']}`
52
51
  }
53
52
  return config;
54
53
  })