ui: check if spot ext exists on login comp

This commit is contained in:
nick-delirium 2025-04-14 09:38:33 +02:00 committed by Delirium
parent 3272f5b9fd
commit e32dbe2ee2
2 changed files with 32 additions and 2 deletions

View file

@ -13,6 +13,7 @@ import { useStore } from 'App/mstore';
import LanguageSwitcher from '../LanguageSwitcher';
import withCaptcha, { WithCaptchaProps } from 'App/withRecaptcha';
import SSOLogin from './SSOLogin';
import { extKey } from 'Components/Spots/SpotsList/InstallCTA';
const FORGOT_PASSWORD = forgotPassword();
const SIGNUP_ROUTE = signup();
@ -30,6 +31,7 @@ function Login({
const { t } = useTranslation();
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [extExist, setExtExist] = useState<boolean>(false);
const { loginStore, userStore } = useStore();
const { errors } = userStore.loginRequest;
const { loading } = loginStore;
@ -38,6 +40,33 @@ function Login({
const history = useHistory();
const params = new URLSearchParams(location.search);
useEffect(() => {
let int: any;
const v = localStorage.getItem(extKey);
if (v) {
setExtExist(true);
} else {
int = setInterval(() => {
window.postMessage({ type: 'orspot:ping' }, '*');
});
const onSpotMsg = (e: any) => {
if (e.data.type === 'orspot:pong') {
setExtExist(true);
localStorage.setItem(extKey, '1');
clearInterval(int);
int = null;
window.removeEventListener('message', onSpotMsg);
}
};
window.addEventListener('message', onSpotMsg);
}
return () => {
if (int) {
clearInterval(int);
}
};
}, []);
useEffect(() => {
if (authDetails && !authDetails.tenants) {
history.push(SIGNUP_ROUTE);
@ -63,7 +92,7 @@ function Login({
let int: ReturnType<typeof setInterval>;
const onSpotMsg = (event: any) => {
if (event.data.type === 'orspot:logged') {
if (event.data.type === 'orspot:logged' && extExist) {
clearInterval(int);
window.removeEventListener('message', onSpotMsg);
const msg = t('You have been logged into Spot successfully')

View file

@ -4,9 +4,10 @@ import { Alert, Button } from 'antd';
import { ArrowUpRight } from 'lucide-react';
import { useTranslation } from 'react-i18next';
export const extKey = '__$spot_ext_exist$__';
function InstallCTA() {
const { t } = useTranslation();
const extKey = '__$spot_ext_exist$__';
const [extExist, setExtExist] = React.useState<boolean>(false);
const isChromium =
// @ts-ignore