Files
EpicNext-Cms/src/app/(site)/login/page.tsx
T
openhands c432d4e95d
Deploy / release (push) Skipped
Deploy / deploy (push) Successful in 1m53s
fix: service worker cache busting — unregister old sw on load, bump cache version, stop caching HTML
- Bump sw.js cache from v2 to v3
- Unregister all old service workers on page load
- Stop caching HTML/navigation (caused stale CSS refs after rebuild)
2026-07-24 13:50:45 +02:00

284 lines
10 KiB
TypeScript

import { headers } from "next/headers";
import Image from "next/image";
import Link from "next/link";
import { getTranslations } from "next-intl/server";
import { LoginForm } from "@/components/auth/login-form";
import { cached } from "@/lib/cache";
import { avatarImageUrl } from "@/lib/format";
import { prisma } from "@/lib/prisma";
import { captchaConfig } from "@/lib/services/captcha";
import { resolveHotelName } from "@/lib/hotel-name";
import { siteSettings } from "@/lib/services/site-settings";
import { ThemeSwitcher } from "@/components/theme-switcher";
import { LanguageSwitcher } from "@/components/language-switcher";
import { Reveal } from "@/components/motion-reveal";
import { Clock } from "@/components/clock";
export default async function LoginPage() {
const t = await getTranslations("pages.login");
const th = await getTranslations("header");
const [hotelName, imagerRaw, cfg, discordUrl, logo] = await Promise.all([
resolveHotelName(),
siteSettings.get(
"habbo_imaging_url",
"https://www.habbo.com/habbo-imaging/avatarimage",
),
captchaConfig(),
siteSettings.get("radio_social_discord", ""),
siteSettings.get("cms_logo", ""),
]);
const imager = imagerRaw ?? "https://www.habbo.com/habbo-imaging/avatarimage";
const nonce = (await headers()).get("x-nonce") ?? undefined;
const [online, recentUsers, latestUsers] = await Promise.all([
cached("online_count", 10_000, () =>
prisma.user.count({ where: { online: "1" } }),
).catch(() => 0),
prisma.user
.findMany({
where: { online: "1" },
select: { username: true, look: true },
take: 8,
})
.catch(() => []),
prisma.user
.findMany({
orderBy: { accountCreated: "desc" },
select: { username: true, look: true },
take: 8,
})
.catch(() => []),
]);
return (
<div className="flex flex-col gap-10 pb-14">
{/* ── Top Bar ── */}
<Reveal>
<div className="relative flex items-center justify-between rounded-xl border px-5 py-3" style={{
background: "color-mix(in srgb, var(--color-surface) 60%, transparent)",
backdropFilter: "blur(14px)",
WebkitBackdropFilter: "blur(14px)",
borderColor: "color-mix(in srgb, var(--color-text-muted) 8%, transparent)",
}}>
<div className="flex items-center gap-3">
{logo ? (
<Image src={logo} alt={hotelName} width={100} height={28} className="shrink-0 object-contain" unoptimized style={{ maxHeight: 28, width: "auto", height: "auto" }} />
) : (
<Image src="/assets/images/icons/lighthouse.png" alt={hotelName} width={28} height={28} className="shrink-0" unoptimized />
)}
<span className="text-sm font-extrabold uppercase tracking-wide" style={{ color: "var(--color-text-readable)" }}>
{hotelName}
</span>
</div>
<div className="flex items-center gap-1.5 rounded-lg px-2 py-1" style={{
background: "color-mix(in srgb, var(--color-text-muted) 4%, transparent)",
}}>
<LanguageSwitcher />
<div className="w-px h-5" style={{ background: "color-mix(in srgb, var(--color-text-muted) 12%, transparent)" }} />
<Clock />
<div className="w-px h-5" style={{ background: "color-mix(in srgb, var(--color-text-muted) 12%, transparent)" }} />
<ThemeSwitcher />
</div>
</div>
</Reveal>
<Reveal>
<div className="flex flex-col lg:flex-row gap-10 stagger-children">
{/* Left panel */}
<div className="lg:w-80 shrink-0 space-y-4">
<div
className="relative overflow-hidden rounded-2xl border p-6 text-center card-premium"
style={{
borderColor: "color-mix(in srgb, var(--color-primary) 20%, transparent)",
background: `url(/assets/images/background.png) center/cover no-repeat`,
}}
>
<div
className="absolute inset-0"
style={{
background: "linear-gradient(135deg, color-mix(in srgb, var(--color-surface) 85%, transparent) 0%, color-mix(in srgb, var(--color-surface) 40%, transparent) 100%)",
}}
/>
<div className="relative">
<Image
src="/assets/images/FrankwithBag.gif"
alt="Frank"
width={130}
height={170}
className="object-contain mx-auto drop-shadow-xl animate-float"
unoptimized
priority
/>
<div
className="inline-flex items-center gap-2 px-3.5 py-1 rounded-full text-xs font-bold uppercase tracking-wider mt-4 mb-3 border backdrop-blur-sm"
style={{
borderColor: "color-mix(in srgb, var(--color-primary) 18%, transparent)",
background: "color-mix(in srgb, var(--color-primary) 10%, transparent)",
color: "var(--color-primary-readable, var(--color-primary))",
}}
>
<span className="relative flex h-2 w-2">
<span className="animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75" />
<span className="relative inline-flex rounded-full h-2 w-2 bg-green-500" />
</span>
{th("online", { count: online, hotel: "" }).trim()}
</div>
<h1
className="text-xl font-black"
style={{ color: "var(--color-text-readable)", fontFamily: "var(--font-nunito)" }}
>
{t("welcomeBack")}
</h1>
<p
className="text-xs mt-1 mx-auto max-w-[200px] leading-relaxed"
style={{ color: "var(--color-text-muted)" }}
>
{t("welcomeBackSub", { hotelName })}
</p>
</div>
</div>
{recentUsers.length > 0 && (
<div
className="overflow-hidden rounded-xl border"
style={{ borderColor: "color-mix(in srgb, var(--color-text-muted) 12%, transparent)" }}
>
<div
className="flex items-center gap-2.5 px-4 py-3"
style={{
background: "linear-gradient(140deg, #0A1F0A 0%, #0F2D0F 20%, #153C15 40%, #1B4A1B 60%, #205820 75%, #1A4A1A 90%, #143814 100%)",
}}
>
<Image src="/assets/images/icons/navigation/goody.png" alt="" width={18} height={18} unoptimized />
<h3 className="text-sm font-bold text-white" style={{ fontFamily: "var(--font-nunito)" }}>
{th("online", { count: online, hotel: "" }).trim()}
</h3>
</div>
<div className="p-4" style={{ background: "color-mix(in srgb, var(--color-surface) 70%, transparent)" }}>
<div className="grid grid-cols-4 gap-1.5">
{recentUsers.map((u) => (
<div
key={u.username}
className="flex flex-col items-center gap-0.5 p-1.5 rounded-lg"
style={{
background: "color-mix(in srgb, var(--color-primary) 4%, transparent)",
}}
>
<Image
src={avatarImageUrl(imager, u.look, { headOnly: true, direction: 2, size: "s" })}
alt=""
width={26}
height={32}
className="rounded-md"
unoptimized
/>
<span
className="text-[8px] font-bold truncate w-full text-center leading-tight"
style={{ color: "var(--color-text-readable)" }}
>
{u.username}
</span>
</div>
))}
</div>
</div>
</div>
)}
{latestUsers.length > 0 && (
<div
className="overflow-hidden rounded-xl border"
style={{ borderColor: "color-mix(in srgb, var(--color-text-muted) 12%, transparent)" }}
>
<div
className="flex items-center gap-2.5 px-4 py-3"
style={{
background: "linear-gradient(140deg, #5a2d82 0%, #6b3a9e 20%, #7d47b8 40%, #8f54d0 60%, #7d47b8 75%, #6b3a9e 90%, #5a2d82 100%)",
}}
>
<Image src="/assets/images/icons/friends.png" alt="" width={18} height={18} unoptimized />
<h3 className="text-sm font-bold text-white" style={{ fontFamily: "var(--font-nunito)" }}>
Newest citizens
</h3>
</div>
<div className="p-4" style={{ background: "color-mix(in srgb, var(--color-surface) 70%, transparent)" }}>
<div className="grid grid-cols-4 gap-1.5">
{latestUsers.map((u) => (
<div
key={u.username}
className="flex flex-col items-center gap-0.5 p-1.5 rounded-lg"
style={{
background: "color-mix(in srgb, var(--color-primary) 4%, transparent)",
}}
>
<Image
src={avatarImageUrl(imager, u.look, { headOnly: true, direction: 2, size: "s" })}
alt=""
width={26}
height={32}
className="rounded-md"
unoptimized
/>
<span
className="text-[8px] font-bold truncate w-full text-center leading-tight"
style={{ color: "var(--color-text-readable)" }}
>
{u.username}
</span>
</div>
))}
</div>
</div>
</div>
)}
<p className="text-xs text-center" style={{ color: "var(--color-text-muted)" }}>
{t("noAccount") ?? "No account?"}{" "}
<Link
href="/register"
className="font-extrabold hover:underline"
style={{ color: "var(--color-primary-readable, var(--color-primary))" }}
>
{t("createOne") ?? "Create one"}
</Link>
</p>
</div>
{/* Right: form */}
<div className="flex-1">
<div className="overflow-hidden rounded-xl border" style={{ borderColor: "color-mix(in srgb, var(--color-text-muted) 12%, transparent)" }}>
<div
className="flex items-center gap-2.5 px-4 py-3"
style={{
background: "linear-gradient(140deg, #1a3a5c 0%, #1e4a6e 20%, #2a5a80 40%, #3a6a90 60%, #4a7aa0 75%, #3a6a90 90%, #2a5a80 100%)",
}}
>
<Image src="/assets/images/icons/navigation/me.png" alt="" width={18} height={18} unoptimized />
<h2 className="text-sm font-bold text-white" style={{ fontFamily: "var(--font-nunito)" }}>
{t("title")}
</h2>
</div>
<div className="p-6" style={{ backgroundColor: "var(--color-surface)" }}>
<p
className="text-sm mb-6"
style={{ color: "var(--color-text-muted)" }}
>
{t("subtitle")}
</p>
<LoginForm
captcha={{
provider: cfg.provider,
siteKey: cfg.siteKey || undefined,
field: cfg.field || undefined,
}}
nonce={nonce}
/>
</div>
</div>
</div>
</div>
</Reveal>
</div>
);
}