()
| 291 | } |
| 292 | |
| 293 | export function relog() { |
| 294 | const token = cookie.load("brewToken"); |
| 295 | return (dispatch) => { |
| 296 | if (!token) { |
| 297 | if (authenticatePage()) { |
| 298 | window.location.pathname = "/login"; |
| 299 | } |
| 300 | return new Promise((resolve, reject) => reject("Token is missing")); |
| 301 | } |
| 302 | |
| 303 | const headers = new Headers({ |
| 304 | "Accept": "application/json", |
| 305 | "Content-Type": "application/json", |
| 306 | "authorization": `Bearer ${token}`, |
| 307 | }); |
| 308 | const method = "POST"; |
| 309 | const url = `${API_HOST}/user/relog`; |
| 310 | |
| 311 | return fetch(url, { method, headers }) |
| 312 | .then((response) => { |
| 313 | if (!response.ok) { |
| 314 | dispatch(addError(response.status)); |
| 315 | return new Promise((resolve, reject) => reject("Couldn't relog")); |
| 316 | } |
| 317 | return response.json(); |
| 318 | }) |
| 319 | .then((user) => { |
| 320 | dispatch(saveUser(user)); |
| 321 | redirectToDashboard(); |
| 322 | return new Promise(resolve => resolve(user)); |
| 323 | }) |
| 324 | .catch(() => { |
| 325 | if (authenticatePage()) { |
| 326 | window.location.pathname = "/login"; |
| 327 | } |
| 328 | return new Promise((resolve, reject) => reject("Can't authenticate the user")); |
| 329 | }); |
| 330 | }; |
| 331 | } |
| 332 | |
| 333 | export function getPendingInvites(id) { |
| 334 | // get team invites for a specific user |
no test coverage detected