@sowell/quasar-app-extension-auth 0.2.1 → 0.2.2
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 +1 -1
- package/src/boot/router-guards.ts +3 -1
- package/src/boot/store.ts +2 -2
- package/src/components/pages/Auth.vue +3 -11
- package/src/interfaces/TokenStateInterface.ts +11 -0
- package/src/interfaces/index.ts +1 -1
- package/src/store/index.ts +51 -11
- package/src/interfaces/AuthState.ts +0 -7
- package/src/store/actions.ts +0 -13
- package/src/store/getters.ts +0 -13
- package/src/store/mutations.ts +0 -13
- package/src/store/state.ts +0 -12
package/package.json
CHANGED
|
@@ -9,8 +9,10 @@ export default boot(({ router, store }: BootInterface) => {
|
|
|
9
9
|
} = prompts;
|
|
10
10
|
|
|
11
11
|
router.beforeEach((to, from, next) => {
|
|
12
|
-
|
|
12
|
+
let isValid = store.getters["token/getIsValid"]
|
|
13
|
+
let token = store.getters["token/getRaw"]
|
|
13
14
|
if (
|
|
15
|
+
!isValid &&
|
|
14
16
|
!token &&
|
|
15
17
|
to.path !== LOCAL_LOGIN_ROUTE &&
|
|
16
18
|
to.path !== LOCAL_CHECK_CODE_ROUTE
|
package/src/boot/store.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
//@ts-ignore
|
|
2
2
|
import { boot } from "quasar/wrappers";
|
|
3
3
|
import { BootInterface } from "../interfaces";
|
|
4
|
-
import
|
|
4
|
+
import tokenModule from "../store";
|
|
5
5
|
|
|
6
6
|
export default boot(({ app, store }: BootInterface) => {
|
|
7
7
|
// Register store module
|
|
8
|
-
store.registerModule("
|
|
8
|
+
store.registerModule("token", tokenModule);
|
|
9
9
|
app.provide("$store", store);
|
|
10
10
|
});
|
|
@@ -136,11 +136,11 @@ export default defineComponent({
|
|
|
136
136
|
} = $prompts();
|
|
137
137
|
const $q = useQuasar();
|
|
138
138
|
const { push, replace } = $router();
|
|
139
|
-
const {
|
|
139
|
+
const { dispatch, getters } = $store();
|
|
140
140
|
const { t } = useI18n();
|
|
141
141
|
|
|
142
142
|
onMounted(() => {
|
|
143
|
-
if (
|
|
143
|
+
if (getters["token/getRaw"]) {
|
|
144
144
|
replace(LOCAL_SUCCESS_REDIRECTION_ROUTE);
|
|
145
145
|
}
|
|
146
146
|
});
|
|
@@ -188,11 +188,7 @@ export default defineComponent({
|
|
|
188
188
|
post(AUTH_SERVER_SIGNING_ROUTE, data)
|
|
189
189
|
.then((response: AxiosResponse) => {
|
|
190
190
|
const token = response.data.jwt;
|
|
191
|
-
dispatch("
|
|
192
|
-
const payload = parseJwt(token);
|
|
193
|
-
const user = { roles: payload.roles };
|
|
194
|
-
dispatch("auth/updateUser", user);
|
|
195
|
-
|
|
191
|
+
dispatch("token/updateRaw", token);
|
|
196
192
|
push(LOCAL_SUCCESS_REDIRECTION_ROUTE);
|
|
197
193
|
})
|
|
198
194
|
.catch((error: AxiosError) => {
|
|
@@ -214,10 +210,6 @@ export default defineComponent({
|
|
|
214
210
|
);
|
|
215
211
|
};
|
|
216
212
|
|
|
217
|
-
const parseJwt = (token: string) => {
|
|
218
|
-
return JSON.parse(window.atob(token.split(".")[1]));
|
|
219
|
-
};
|
|
220
|
-
|
|
221
213
|
return {
|
|
222
214
|
email,
|
|
223
215
|
password,
|
package/src/interfaces/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "./Boot";
|
|
2
|
-
export * from "./
|
|
2
|
+
export * from "./TokenStateInterface";
|
package/src/store/index.ts
CHANGED
|
@@ -1,16 +1,56 @@
|
|
|
1
|
-
import { Module } from "vuex";
|
|
2
|
-
import
|
|
3
|
-
import actions from "./actions";
|
|
4
|
-
import getters from "./getters";
|
|
5
|
-
import mutations from "./mutations";
|
|
6
|
-
import { AuthStateInterface } from "../interfaces";
|
|
1
|
+
import { Module, GetterTree, MutationTree, ActionTree } from "vuex";
|
|
2
|
+
import { tokenStateInterface, payload } from "../interfaces";
|
|
7
3
|
|
|
8
|
-
const
|
|
4
|
+
const state: tokenStateInterface = {
|
|
5
|
+
raw: "",
|
|
6
|
+
payload: {
|
|
7
|
+
company_hp: undefined,
|
|
8
|
+
exp: undefined,
|
|
9
|
+
gm_key: "",
|
|
10
|
+
roles: [],
|
|
11
|
+
sub: null
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const getters: GetterTree<tokenStateInterface, any> = {
|
|
16
|
+
getRaw(state) {
|
|
17
|
+
return state.raw
|
|
18
|
+
},
|
|
19
|
+
getPayload(state) {
|
|
20
|
+
return state.payload
|
|
21
|
+
},
|
|
22
|
+
getIsValid(state) {
|
|
23
|
+
if (state.payload.exp) {
|
|
24
|
+
return new Date(state.payload.exp * 1000) >= new Date() ? true : false;
|
|
25
|
+
} else {
|
|
26
|
+
return false
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const mutations: MutationTree<tokenStateInterface> = {
|
|
32
|
+
setRaw(state, value: string) {
|
|
33
|
+
state.raw = value
|
|
34
|
+
},
|
|
35
|
+
setPayload(state, value: payload) {
|
|
36
|
+
state.payload = {...value}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const actions: ActionTree<tokenStateInterface, any> = {
|
|
41
|
+
updateRaw({ commit }, value: string) {
|
|
42
|
+
commit("setRaw", value);
|
|
43
|
+
const parseJwt = JSON.parse(window.atob(value.split(".")[1]));
|
|
44
|
+
commit("setPayload", parseJwt)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const tokenModule: Module<tokenStateInterface, any> = {
|
|
9
49
|
namespaced: true,
|
|
10
|
-
actions,
|
|
11
50
|
getters,
|
|
12
51
|
mutations,
|
|
13
|
-
|
|
14
|
-
|
|
52
|
+
actions,
|
|
53
|
+
state
|
|
54
|
+
}
|
|
15
55
|
|
|
16
|
-
export default
|
|
56
|
+
export default tokenModule;
|
package/src/store/actions.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ActionTree } from "vuex";
|
|
2
|
-
import { AuthStateInterface, UserInterface } from "../interfaces";
|
|
3
|
-
|
|
4
|
-
const actions: ActionTree<AuthStateInterface, any> = {
|
|
5
|
-
updateToken({ commit }, value: string) {
|
|
6
|
-
commit("setToken", value);
|
|
7
|
-
},
|
|
8
|
-
updateUser({ commit }, value: UserInterface) {
|
|
9
|
-
commit("setUser", value);
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export default actions;
|
package/src/store/getters.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { GetterTree } from "vuex";
|
|
2
|
-
import { AuthStateInterface } from "../interfaces";
|
|
3
|
-
|
|
4
|
-
const getters: GetterTree<AuthStateInterface, any> = {
|
|
5
|
-
getToken(state) {
|
|
6
|
-
return state.token;
|
|
7
|
-
},
|
|
8
|
-
getUser(state) {
|
|
9
|
-
return state.user;
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export default getters;
|
package/src/store/mutations.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { MutationTree } from "vuex";
|
|
2
|
-
import { AuthStateInterface, UserInterface } from "../interfaces";
|
|
3
|
-
|
|
4
|
-
const mutation: MutationTree<AuthStateInterface> = {
|
|
5
|
-
setToken(state, value: string) {
|
|
6
|
-
return (state.token = value);
|
|
7
|
-
},
|
|
8
|
-
setUser(state, value: UserInterface) {
|
|
9
|
-
return (state.user = value);
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export default mutation;
|