mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 01:35:39 -04:00
Improve fresh install flow and auth page routing
- Move /setup out of protected (pages) route group so it's accessible without auth (fixes fresh install redirect loop) - Redirect /login → /register when zero users exist - Add "Get Started" button on landing page for fresh installs - Hide register button/link when registration is closed - Add auth redirects: logged-in users on /login or /register → /dashboard - Convert register page to server component with server-side checks - Fix animation snap on auth form buttons (transition-all → scoped) - Update proxy middleware with /login and /register routes Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,11 +1,22 @@
|
||||
import { headers } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
import { AuthForm } from "@/components/auth-form";
|
||||
import { auth } from "@/lib/auth/server";
|
||||
import {
|
||||
getOidcProviderName,
|
||||
isOidcConfigured,
|
||||
isPasswordLoginDisabled,
|
||||
} from "@/lib/config";
|
||||
import { getUserCount, isRegistrationOpen } from "@/lib/services/settings";
|
||||
|
||||
export default async function LoginPage() {
|
||||
const session = await auth.api.getSession({ headers: await headers() });
|
||||
if (session) redirect("/dashboard");
|
||||
|
||||
if (getUserCount() === 0) {
|
||||
redirect("/register");
|
||||
}
|
||||
|
||||
export default function LoginPage() {
|
||||
const oidcEnabled = isOidcConfigured();
|
||||
|
||||
return (
|
||||
@@ -16,6 +27,7 @@ export default function LoginPage() {
|
||||
oidcEnabled,
|
||||
oidcProviderName: oidcEnabled ? getOidcProviderName() : null,
|
||||
passwordLoginDisabled: isPasswordLoginDisabled(),
|
||||
registrationOpen: isRegistrationOpen(),
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -1,55 +1,26 @@
|
||||
"use client";
|
||||
|
||||
import { IconLock } from "@tabler/icons-react";
|
||||
import { motion } from "motion/react";
|
||||
import { headers } from "next/headers";
|
||||
import Link from "next/link";
|
||||
import { useEffect, useState } from "react";
|
||||
import type { AuthConfig } from "@/components/auth-form";
|
||||
import { redirect } from "next/navigation";
|
||||
import { AuthForm } from "@/components/auth-form";
|
||||
import { auth } from "@/lib/auth/server";
|
||||
import {
|
||||
getOidcProviderName,
|
||||
isOidcConfigured,
|
||||
isPasswordLoginDisabled,
|
||||
} from "@/lib/config";
|
||||
import { isRegistrationOpen } from "@/lib/services/settings";
|
||||
|
||||
export default function RegisterPage() {
|
||||
const [registrationOpen, setRegistrationOpen] = useState<boolean | null>(
|
||||
null,
|
||||
);
|
||||
const [authConfig, setAuthConfig] = useState<AuthConfig>({
|
||||
oidcEnabled: false,
|
||||
oidcProviderName: null,
|
||||
passwordLoginDisabled: false,
|
||||
});
|
||||
export default async function RegisterPage() {
|
||||
const session = await auth.api.getSession({ headers: await headers() });
|
||||
if (session) redirect("/dashboard");
|
||||
|
||||
useEffect(() => {
|
||||
fetch("/api/registration/status")
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
setRegistrationOpen(data.registrationOpen);
|
||||
setAuthConfig({
|
||||
oidcEnabled: data.oidcEnabled ?? false,
|
||||
oidcProviderName: data.oidcProviderName ?? null,
|
||||
passwordLoginDisabled: data.passwordLoginDisabled ?? false,
|
||||
});
|
||||
})
|
||||
.catch(() => setRegistrationOpen(false));
|
||||
}, []);
|
||||
|
||||
if (registrationOpen === null) {
|
||||
return <div className="flex min-h-[80vh] items-center justify-center" />;
|
||||
}
|
||||
|
||||
if (!registrationOpen) {
|
||||
if (!isRegistrationOpen()) {
|
||||
return (
|
||||
<div className="flex min-h-[80vh] items-center justify-center px-4">
|
||||
<div className="relative mx-auto w-full max-w-sm">
|
||||
<div className="absolute -inset-4 rounded-2xl bg-primary/3 blur-2xl" />
|
||||
<motion.div
|
||||
className="relative space-y-6 rounded-xl border border-border/50 bg-card/80 p-8 text-center backdrop-blur-sm"
|
||||
initial={{ opacity: 0, y: 20, scale: 0.98 }}
|
||||
animate={{ opacity: 1, y: 0, scale: 1 }}
|
||||
transition={{
|
||||
type: "spring" as const,
|
||||
stiffness: 200,
|
||||
damping: 20,
|
||||
}}
|
||||
>
|
||||
<div className="relative space-y-6 rounded-xl border border-border/50 bg-card/80 p-8 text-center backdrop-blur-sm">
|
||||
<div className="mx-auto flex h-12 w-12 items-center justify-center rounded-full bg-primary/10">
|
||||
<IconLock className="size-6 text-primary" />
|
||||
</div>
|
||||
@@ -68,15 +39,24 @@ export default function RegisterPage() {
|
||||
>
|
||||
Sign in instead
|
||||
</Link>
|
||||
</motion.div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const oidcEnabled = isOidcConfigured();
|
||||
|
||||
return (
|
||||
<div className="flex min-h-[80vh] items-center justify-center px-4">
|
||||
<AuthForm mode="register" authConfig={authConfig} />
|
||||
<AuthForm
|
||||
mode="register"
|
||||
authConfig={{
|
||||
oidcEnabled,
|
||||
oidcProviderName: oidcEnabled ? getOidcProviderName() : null,
|
||||
passwordLoginDisabled: isPasswordLoginDisabled(),
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
+12
-2
@@ -1,4 +1,6 @@
|
||||
import { connection } from "next/server";
|
||||
import { LandingPage } from "@/components/landing-page";
|
||||
import { getUserCount, isRegistrationOpen } from "@/lib/services/settings";
|
||||
import { tmdbImageUrl } from "@/lib/tmdb/image";
|
||||
|
||||
// Well-known TMDB poster paths for the background collage
|
||||
@@ -21,6 +23,14 @@ const posterUrls = posterPaths
|
||||
.map((p) => tmdbImageUrl(p, "w300"))
|
||||
.filter(Boolean) as string[];
|
||||
|
||||
export default function Home() {
|
||||
return <LandingPage posterUrls={posterUrls} />;
|
||||
export default async function Home() {
|
||||
await connection();
|
||||
const userCount = getUserCount();
|
||||
return (
|
||||
<LandingPage
|
||||
posterUrls={posterUrls}
|
||||
freshInstall={userCount === 0}
|
||||
registrationOpen={isRegistrationOpen()}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user