Fixed Themes not showing
This commit is contained in:
@@ -12,16 +12,34 @@ import {
|
||||
setSessionContext,
|
||||
SESSION_COOKIE,
|
||||
} from "@/lib/auth"
|
||||
import { checkRateLimit } from "@/lib/rate-limit"
|
||||
|
||||
function jsonResponse(data: unknown, status: number) {
|
||||
function jsonResponse(data: unknown, status: number, headers?: Record<string, string>) {
|
||||
return new Response(JSON.stringify(data), {
|
||||
status,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
headers: { "Content-Type": "application/json", ...headers },
|
||||
})
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const ipAddress =
|
||||
request.headers.get("x-forwarded-for")?.split(",")[0]?.trim() ||
|
||||
request.headers.get("x-real-ip") ||
|
||||
"127.0.0.1"
|
||||
|
||||
const rateCheck = checkRateLimit(`login:${ipAddress}`, 10, 60000)
|
||||
if (!rateCheck.allowed) {
|
||||
return jsonResponse(
|
||||
{ error: "Too many login attempts. Try again in 60 seconds." },
|
||||
429,
|
||||
{
|
||||
"Retry-After": String(Math.ceil((rateCheck.resetAt - Date.now()) / 1000)),
|
||||
"X-RateLimit-Remaining": "0",
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
const { email, username, password } = await request.json()
|
||||
|
||||
const credential = email || username
|
||||
@@ -40,11 +58,6 @@ export async function POST(request: NextRequest) {
|
||||
)
|
||||
}
|
||||
|
||||
const ipAddress =
|
||||
request.headers.get("x-forwarded-for")?.split(",")[0]?.trim() ||
|
||||
request.headers.get("x-real-ip") ||
|
||||
"127.0.0.1"
|
||||
|
||||
const userAgent = request.headers.get("user-agent") || null
|
||||
|
||||
// Try to find user by email first, then by username
|
||||
|
||||
@@ -34,9 +34,19 @@ function LoginForm() {
|
||||
const [remember, setRemember] = useState(false)
|
||||
const [error, setError] = useState("")
|
||||
const [counts, setCounts] = useState({ leads: 0, conversion: 0, users: 0 })
|
||||
const [checkingSession, setCheckingSession] = useState(true)
|
||||
const counterStarted = useRef(false)
|
||||
const [testimonialIndex, setTestimonialIndex] = useState(0)
|
||||
|
||||
useEffect(() => {
|
||||
fetch("/api/auth/me", { credentials: "include" })
|
||||
.then((r) => {
|
||||
if (r.ok) router.push("/dashboard")
|
||||
else setCheckingSession(false)
|
||||
})
|
||||
.catch(() => setCheckingSession(false))
|
||||
}, [router])
|
||||
|
||||
const testimonials = [
|
||||
{
|
||||
text: "This CRM transformed how we manage our sales pipeline. We've seen a 40% increase in lead conversion.",
|
||||
@@ -240,6 +250,14 @@ function LoginForm() {
|
||||
}
|
||||
}
|
||||
|
||||
if (checkingSession) {
|
||||
return (
|
||||
<div className="flex min-h-screen bg-[#0a0a0f] items-center justify-center">
|
||||
<div className="w-8 h-8 border-2 border-[#1BB0CE] border-t-transparent rounded-full animate-spin" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex min-h-screen bg-[#0a0a0f]">
|
||||
<div className="left-panel flex flex-1 flex-col p-12">
|
||||
|
||||
Reference in New Issue
Block a user