smplify token validation
This commit is contained in:
@@ -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()
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user