Files
Cosmos-Server/client/src/isLoggedIn.jsx
Kawanaao 87c1636ff7 [skip ci] Optimizations/react (#186)
* Replaced the lodash module with submodules

* Using lazy imports of heavy modules

* Replaced the old authorization verification system with PrivateRoute

* Dynamic import of all paths

* Minifying the syntax highlighting library

* Added missing imports

* Added expires to head meta

* Don't force the code to follow unnecessary redirects

* Kawanaao accept CLA

---------

Co-authored-by: Yann S <7872597+azukaar@users.noreply.github.com>
2024-02-04 12:43:27 +00:00

26 lines
947 B
JavaScript

import * as API from './api';
async function isLoggedIn() {
const urlSearch = encodeURIComponent(window.location.search);
const redirectToURL = (window.location.pathname + urlSearch);
const data = await API.auth.me();
if (data.status == 'NEW_INSTALL') {
return '/cosmos-ui/newInstall';
} else if (data.status == 'error' && data.code == "HTTP004") {
return '/cosmos-ui/login?redirect=' + redirectToURL;
} else if (data.status == 'error' && data.code == "HTTP006") {
return '/cosmos-ui/loginmfa?redirect=' + redirectToURL;
} else if (data.status == 'error' && data.code == "HTTP007") {
return '/cosmos-ui/newmfa?redirect=' + redirectToURL;
} else if (data.status == 'OK') {
return data.status
} else {
console.warn(`Status "${data.status}" does not have a navigation handler, will be interpreted as OK!`)
return 'OK'
}
};
export default isLoggedIn;