orderiom-api-package 0.4.96 → 0.4.98
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 +8 -2
package/package.json
CHANGED
package/src/common.js
CHANGED
|
@@ -178,16 +178,22 @@ export const defineInterceptors = ({$store}) => {
|
|
|
178
178
|
if(idFromEnv && !data.restaurantId) data.restaurantId = idFromEnv;
|
|
179
179
|
config[key] = data;
|
|
180
180
|
|
|
181
|
+
const userId = $store.state.orderiomApiPackage.auth.user.id;
|
|
182
|
+
|
|
181
183
|
// use the valid token if possible
|
|
182
184
|
let token = localStorage.getItem("privateToken") || localStorage.getItem("publicToken");
|
|
183
|
-
if(
|
|
185
|
+
if(
|
|
186
|
+
token &&
|
|
187
|
+
!isTokenExpired(token) &&
|
|
188
|
+
(!userId || localStorage.getItem("privateToken")) // if userId exists then private token must exist too
|
|
189
|
+
){
|
|
184
190
|
config.headers["Authorization"] = `Bearer ${token}`
|
|
185
191
|
return config;
|
|
186
192
|
}
|
|
187
193
|
|
|
188
194
|
// if the token is expired or does not exist, wait for public token to be fetched
|
|
189
195
|
return new Promise((resolve, reject) => {
|
|
190
|
-
const hadPrivateToken =
|
|
196
|
+
const hadPrivateToken = Boolean(localStorage.getItem("privateToken") || userId);
|
|
191
197
|
// remove invalid or expired tokens
|
|
192
198
|
token = null;
|
|
193
199
|
localStorage.removeItem("privateToken");
|