mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-29 16:14:43 +00:00
useAuth Integration
This commit is contained in:
@@ -8,6 +8,7 @@ const useAuth = () => {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [username, setUsername] = useState("");
|
||||
const [name, setName] = useState("");
|
||||
const [email, setEmail] = useState("");
|
||||
const router = useRouter();
|
||||
|
||||
const validate = useCallback(async () => {
|
||||
@@ -18,25 +19,28 @@ const useAuth = () => {
|
||||
setLoading(false);
|
||||
setValidated(false);
|
||||
router.push("/");
|
||||
return;
|
||||
return "Invalid";
|
||||
}
|
||||
|
||||
const response = await axios.post("/api/user/validate", { token });
|
||||
|
||||
if (response.data.message === "Valid") {
|
||||
setValidated(true);
|
||||
setUsername(response.data.username);
|
||||
setName(response.data.name);
|
||||
setEmail(response.data.email);
|
||||
return "Validated";
|
||||
} else {
|
||||
setValidated(false);
|
||||
Cookies.remove("token");
|
||||
router.push("/");
|
||||
return "Invalid";
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Validation error:", error);
|
||||
setValidated(false);
|
||||
Cookies.remove("token");
|
||||
router.push("/");
|
||||
return "Invalid";
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -51,9 +55,9 @@ const useAuth = () => {
|
||||
loading,
|
||||
username,
|
||||
name,
|
||||
email,
|
||||
validate
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export default useAuth;
|
||||
Reference in New Issue
Block a user