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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/common.js +8 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orderiom-api-package",
3
- "version": "0.4.96",
3
+ "version": "0.4.98",
4
4
  "description": "This package will install all necessary API calls for every orderiom restaurant",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
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(token && !isTokenExpired(token)){
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 = !!localStorage.getItem("privateToken");
196
+ const hadPrivateToken = Boolean(localStorage.getItem("privateToken") || userId);
191
197
  // remove invalid or expired tokens
192
198
  token = null;
193
199
  localStorage.removeItem("privateToken");