2023-03-12 18:17:28 +00:00
|
|
|
|
|
|
|
import * as API from './api';
|
|
|
|
import { useEffect } from 'react';
|
2023-07-28 09:28:15 +00:00
|
|
|
import { redirectToLocal } from './utils/indexs';
|
2023-03-12 18:17:28 +00:00
|
|
|
|
2023-04-27 18:29:26 +00:00
|
|
|
const IsLoggedIn = () => useEffect(() => {
|
2023-03-16 18:56:36 +00:00
|
|
|
console.log("CHECK LOGIN")
|
2023-06-04 14:41:26 +00:00
|
|
|
const urlSearch = encodeURIComponent(window.location.search);
|
2023-07-28 09:28:15 +00:00
|
|
|
const redirectToURL = (window.location.pathname + urlSearch);
|
2023-06-04 14:41:26 +00:00
|
|
|
|
2023-03-12 18:17:28 +00:00
|
|
|
API.auth.me().then((data) => {
|
|
|
|
if(data.status != 'OK') {
|
2023-03-29 20:38:50 +00:00
|
|
|
if(data.status == 'NEW_INSTALL') {
|
2023-07-28 09:28:15 +00:00
|
|
|
redirectToLocal('/cosmos-ui/newInstall');
|
2023-04-27 18:29:26 +00:00
|
|
|
} else if (data.status == 'error' && data.code == "HTTP004") {
|
2023-07-28 09:28:15 +00:00
|
|
|
redirectToLocal('/cosmos-ui/login?redirect=' + redirectToURL);
|
2023-04-30 12:03:14 +00:00
|
|
|
} else if (data.status == 'error' && data.code == "HTTP006") {
|
2023-07-28 09:28:15 +00:00
|
|
|
redirectToLocal('/cosmos-ui/loginmfa?redirect=' + redirectToURL);
|
2023-04-30 12:03:14 +00:00
|
|
|
} else if (data.status == 'error' && data.code == "HTTP007") {
|
2023-07-28 09:28:15 +00:00
|
|
|
redirectToLocal('/cosmos-ui/newmfa?redirect=' + redirectToURL);
|
2023-04-27 18:29:26 +00:00
|
|
|
}
|
2023-03-12 18:17:28 +00:00
|
|
|
}
|
2023-04-30 16:23:48 +00:00
|
|
|
})
|
2023-03-16 18:56:36 +00:00
|
|
|
}, []);
|
2023-03-12 18:17:28 +00:00
|
|
|
|
2023-04-27 18:29:26 +00:00
|
|
|
export default IsLoggedIn;
|