smplify token validation

This commit is contained in:
tylen
2025-11-01 22:19:09 +02:00
parent b8a0fd9179
commit cef340a679
3 changed files with 24 additions and 19 deletions

View File

@@ -6,8 +6,8 @@ import { useNotification } from '../NotificationContext';
const InitialSetup = () => {
const [cookie, setCookie] = useCookies();
const [selectedName, setSelectedName] = useState<string | undefined>(cookie.userName);
const [token] = useState<string | undefined>(cookie.apiToken)
const [selectedName, setSelectedName] = useState<string | undefined>(undefined);
//const [token] = useState<string | undefined>(cookie.apiToken)
const [isSubmitted, setIsSubmitted] = useState(false);
const [password, setPassword] = useState('');
const [isPasswordSet, setIsPasswordSet] = useState(false); // To track if password is set
@@ -27,13 +27,14 @@ const InitialSetup = () => {
checkUserPassword(name);
};
const validateToken = async () => {
const isTokenValid = await validToken(cookie.apiToken);
setIsSubmitted(isTokenValid);
};
useEffect(() => {
const validateToken = async () => {
const isTokenValid = await validToken(token, selectedName);
setIsSubmitted(isTokenValid);
};
if (token !== undefined && selectedName !== undefined) validateToken();
}, []);
if (cookie.apiToken !== undefined) validateToken();
}, [cookie.apiToken]);
const handlePasswordCreate = async () => {
@@ -42,7 +43,7 @@ const InitialSetup = () => {
notify(message, 'error')
return
}
setIsSubmitted(true);
};
const handleSignIn = async () => {
@@ -51,7 +52,7 @@ const InitialSetup = () => {
notify('Не удалось войти. Может пароль не тот?', 'error')
return
}
setIsSubmitted(true);
validateToken()
};