make auth work correctly

This commit is contained in:
tylen
2025-11-01 11:43:09 +02:00
parent a50a06d371
commit 014a8fc1ff
4 changed files with 163 additions and 22 deletions

View File

@@ -15,17 +15,10 @@ const InitialSetup = () => {
const { userSet, passwordCreate, signUser, validToken } = useFetchUser(); // Destructure functions from the hook
const notify = useNotification();
useEffect(() => {
const validateToken = async () => {
const isTokenValid = await validToken(token, selectedName);
setIsSubmitted(isTokenValid);
};
validateToken();
if (selectedName) {
checkUserPassword(selectedName)
}
}, [selectedName]);
const checkUserPassword = async (name: string) => {
const passwordStatus = await userSet(name);
setIsPasswordSet(passwordStatus);
};
const handleSelect = (event: React.ChangeEvent<HTMLSelectElement>) => {
const name = event.target.value;
@@ -34,10 +27,15 @@ const InitialSetup = () => {
checkUserPassword(name);
};
const checkUserPassword = async (name: string) => {
const passwordStatus = await userSet(name);
setIsPasswordSet(passwordStatus);
};
useEffect(() => {
const validateToken = async () => {
const isTokenValid = await validToken(token, selectedName);
setIsSubmitted(isTokenValid);
};
if (selectedName !== undefined) checkUserPassword(selectedName)
if (token && selectedName) validateToken();
}, [selectedName]);
const handlePasswordCreate = async () => {
const message= await passwordCreate(selectedName!, password);