fix: production login error masking, resolve navbar hydration mismatch, and gracefully handle database render errors
All checks were successful
Staging Build / build (push) Successful in 2m15s
All checks were successful
Staging Build / build (push) Successful in 2m15s
This commit is contained in:
@@ -14,7 +14,7 @@ import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
export function LoginForm({
|
||||
className,
|
||||
@@ -24,8 +24,13 @@ export function LoginForm({
|
||||
const [password, setPassword] = useState("");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [messageParam, setMessageParam] = useState<string | null>(null);
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
setMessageParam(new URLSearchParams(window.location.search).get('message'));
|
||||
}, []);
|
||||
|
||||
const handleLogin = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setIsLoading(true);
|
||||
@@ -35,6 +40,10 @@ export function LoginForm({
|
||||
|
||||
try {
|
||||
const res = await signIn(email, password);
|
||||
if (!res.success) {
|
||||
setError(res.error || "An error occurred");
|
||||
return;
|
||||
}
|
||||
if (nextParam) {
|
||||
router.push(nextParam);
|
||||
} else if (res.role === "admin") {
|
||||
@@ -90,17 +99,11 @@ export function LoginForm({
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
{(() => {
|
||||
const messageParam = typeof window !== 'undefined' ? new URLSearchParams(window.location.search).get('message') : null;
|
||||
if (messageParam === "concurrent") {
|
||||
return (
|
||||
<p className="text-sm text-amber-500 bg-amber-500/10 border border-amber-500/20 p-3 rounded-lg text-center font-medium">
|
||||
Sie wurden abgemeldet, da Sie sich an einem anderen Gerät angemeldet haben.
|
||||
</p>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
})()}
|
||||
{messageParam === "concurrent" && (
|
||||
<p className="text-sm text-amber-500 bg-amber-500/10 border border-amber-500/20 p-3 rounded-lg text-center font-medium">
|
||||
Sie wurden abgemeldet, da Sie sich an einem anderen Gerät angemeldet haben.
|
||||
</p>
|
||||
)}
|
||||
{error && <p className="text-sm text-red-500">{error}</p>}
|
||||
<Button type="submit" className="w-full" disabled={isLoading}>
|
||||
{isLoading ? "Logging in..." : "Login"}
|
||||
|
||||
Reference in New Issue
Block a user