misc / bugfix: session refresh
This commit is contained in:
@@ -22,11 +22,21 @@ export default function LoginPage() {
|
||||
try {
|
||||
if (!username) {
|
||||
setLoading(false);
|
||||
return toast.error("Username is required");
|
||||
if (!toast.isActive("login-username-required-toast")) {
|
||||
return toast.error("Username and password are required",
|
||||
{
|
||||
toastId: "login-missing-data-toast",
|
||||
});
|
||||
}
|
||||
}
|
||||
if (!password) {
|
||||
setLoading(false);
|
||||
return toast.error("Password is required");
|
||||
if (!toast.isActive("login-password-required-toast")) {
|
||||
return toast.error("Username and password are required",
|
||||
{
|
||||
toastId: "login-missing-data-toast",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const formData = new URLSearchParams();
|
||||
@@ -45,28 +55,52 @@ export default function LoginPage() {
|
||||
});
|
||||
|
||||
if (resp.status === 401) {
|
||||
toast.error("Invalid username or password");
|
||||
if (!toast.isActive("login-error-invalid-toast")) {
|
||||
toast.error("Invalid username or password", {
|
||||
toastId: "login-error-invalid-toast",
|
||||
});
|
||||
}
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!resp.ok) {
|
||||
const data = await resp.json().catch(() => ({}));
|
||||
toast.error(data.detail ? `Login failed: ${data.detail}` : "Login failed");
|
||||
if (!toast.isActive("login-error-failed-toast")) {
|
||||
toast.error(data.detail ? `Login failed: ${data.detail}` : "Login failed",
|
||||
{
|
||||
toastId: "login-error-failed-toast",
|
||||
});
|
||||
}
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const data = await resp.json();
|
||||
if (data.access_token) {
|
||||
toast.success("Login successful!");
|
||||
if (!toast.isActive("login-success-toast")) {
|
||||
toast.success("Login successful!",
|
||||
{
|
||||
toastId: "login-success-toast",
|
||||
});
|
||||
}
|
||||
window.location.href = "/TRip"; // TODO: fix, hardcoded
|
||||
} else {
|
||||
toast.error("Login failed: no access token received");
|
||||
setLoading(false);
|
||||
if (!toast.isActive("login-error-no-token-toast")) {
|
||||
toast.error("Login failed: no access token received",
|
||||
{
|
||||
toastId: "login-error-no-token-toast",
|
||||
});
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
toast.error("Network error during login");
|
||||
if (!toast.isActive("login-error-network-toast")) {
|
||||
toast.error("Network error during login",
|
||||
{
|
||||
toastId: "login-error-network-toast",
|
||||
});
|
||||
}
|
||||
console.error("Login error:", error);
|
||||
setLoading(false);
|
||||
}
|
||||
|
Reference in New Issue
Block a user