When I set the number of login authentication attempts to 5, if the user fails to authenticate 5 times, there is no message that the user has been suspended. I tried to add such a message on the front end, I hope to add an error code or use it for the front end.
This is an example of my project and front-end code, the effect is not very ideal.
useAuth.ts
/**
* Get user status via email
* @param email - User Email
* @returns {Promise<"active" | "suspended" | null>} User Status
*/
const getUserStatusByEmail = async (email: string): Promise<"active" | "suspended" | null> => {
try {
const users = await $directus.request(
$user.readUsers({
filter: { email: { _eq: email } },
fields: ["status"],
limit: 1,
})
);
if (users && users.length > 0) {
return users[0]?.status as "active" | "suspended";
}
return null;
} catch (error) {
return null;
}
};
LoginForm.vue
const status = await getUserStatusByEmail(email.value);
if (status === "suspended") {
toast.add({
title: "Login",
description: "Your login has been suspended due to too many login attempts. Please contact the administrator.",
icon: "hugeicons:alert-02",
color: "error",
});
return;
}