orderiom-api-package 0.4.70 → 0.4.71
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/common.js +16 -0
- package/src/modules/auth.js +4 -1
package/package.json
CHANGED
package/src/common.js
CHANGED
|
@@ -112,6 +112,22 @@ export function formatTime(date){
|
|
|
112
112
|
].join(':')
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
export function isTokenExpired(token) {
|
|
116
|
+
const base64Url = token.split(".")[1];
|
|
117
|
+
const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
|
|
118
|
+
const jsonPayload = decodeURIComponent(
|
|
119
|
+
atob(base64)
|
|
120
|
+
.split("")
|
|
121
|
+
.map(function (c) {
|
|
122
|
+
return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
|
|
123
|
+
})
|
|
124
|
+
.join("")
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const { exp } = JSON.parse(jsonPayload);
|
|
128
|
+
return Date.now() >= exp * 1000;
|
|
129
|
+
}
|
|
130
|
+
|
|
115
131
|
axios.defaults.baseURL = process.env.VUE_APP_BASE_API_URL || window.dynamicData.VUE_APP_BASE_API_URL;
|
|
116
132
|
axios.interceptors.request.use(config => {
|
|
117
133
|
const token = localStorage.getItem("privateToken") || localStorage.getItem("publicToken");
|
package/src/modules/auth.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {commonErrorCallback, $http,
|
|
1
|
+
import {commonErrorCallback, $http, isTokenExpired, restaurantIdEnv } from '../common';
|
|
2
2
|
|
|
3
3
|
const state = {
|
|
4
4
|
publicToken: null,
|
|
@@ -53,6 +53,9 @@ const mutations = {
|
|
|
53
53
|
};
|
|
54
54
|
const actions = {
|
|
55
55
|
auth({ commit }) {
|
|
56
|
+
const publicToken = localStorage.getItem('publicToken');
|
|
57
|
+
if(publicToken && !isTokenExpired(publicToken)) return;
|
|
58
|
+
|
|
56
59
|
return $http
|
|
57
60
|
.post("api/oauth/token", {
|
|
58
61
|
grant_type: process.env.VUE_APP_GRANT_TYPE || window.dynamicData.VUE_APP_GRANT_TYPE,
|