Route Buzz Guide login through Sudloh Account
CI / Verify (push) Successful in 3m7s
CI / Build immutable images and deploy (push) Successful in 4m25s

This commit is contained in:
2026-10-05 16:55:38 +07:00 Unverified
parent e2fa1aafb6
commit 6dfa9bbf89
13 changed files with 273 additions and 26 deletions
+3 -2
View File
@@ -5,7 +5,8 @@ export const instant = false;
export default async function LoginPage({ searchParams }: PageProps<"/auth/login">) {
await connection();
const { next, verified, error } = await searchParams;
const { next, verified, error, sudloh } = await searchParams;
const oidcError = sudloh === "1" && typeof error === "string" ? error : undefined;
return <AccountPage mode="login" next={next} verified={verified === "1" && !error}
verificationError={typeof error === "string"} />;
verificationError={typeof error === "string" && !oidcError} oidcError={oidcError} />;
}
+23 -9
View File
@@ -2,29 +2,38 @@ import { eq } from "drizzle-orm";
import { redirect } from "next/navigation";
import { connection } from "next/server";
import { getDb } from "@/db";
import { users } from "@/db/schema";
import { accounts, users } from "@/db/schema";
import { SiteHeader } from "@/components/public/site-header";
import { AdminHeader } from "@/components/admin/admin-header";
import { ProfileForm } from "@/components/auth/profile-form";
import { PasswordForm } from "@/components/auth/password-form";
import { EmailSettings } from "@/components/auth/email-settings";
import { SudlohConnection } from "@/components/auth/sudloh-connection";
import { isAuthorizedAdmin } from "@/lib/auth/authorization";
import { getCustomerSession } from "@/lib/auth/server";
import { getCustomerSession, isSudlohOidcEnabled } from "@/lib/auth/server";
import { safeAuthReturnPath } from "@/lib/auth/return-path";
export const instant = false;
export default async function ProfilePage({ searchParams }: PageProps<"/profile">) {
await connection();
const { setup, next, upload, emailAction, error } = await searchParams;
const { setup, next, upload, emailAction, error, sudloh } = await searchParams;
const nextPath = safeAuthReturnPath(next);
const setupNextPath = nextPath === "/profile" || nextPath.startsWith("/profile?") ? "/" : nextPath;
const session = await getCustomerSession();
if (!session) redirect("/auth/login?next=%2Fprofile");
const [user] = await getDb().select({ name: users.name, email: users.email,
emailVerified: users.emailVerified, image: users.image })
.from(users).where(eq(users.id, session.user.id)).limit(1);
const oidcEnabled = isSudlohOidcEnabled();
const [userRows, accountRows] = await Promise.all([
getDb().select({ name: users.name, email: users.email,
emailVerified: users.emailVerified, image: users.image })
.from(users).where(eq(users.id, session.user.id)).limit(1),
oidcEnabled ? getDb().select({ providerId: accounts.providerId })
.from(accounts).where(eq(accounts.userId, session.user.id)) : Promise.resolve([]),
]);
const [user] = userRows;
if (!user) redirect("/auth/login?next=%2Fprofile");
const hasSudloh = accountRows.some((account) => account.providerId === "sudloh");
const hasCredential = accountRows.some((account) => account.providerId === "credential");
return <div className="min-h-svh">{isAuthorizedAdmin(session.user) ? <AdminHeader /> : <SiteHeader />}
<main className="mx-auto max-w-5xl p-4 py-10 sm:p-8">
<h1 className="mb-6 font-heading text-3xl font-semibold">โปรไฟล์ของฉัน</h1>
@@ -34,9 +43,14 @@ export default async function ProfilePage({ searchParams }: PageProps<"/profile"
</p>}
<div className="grid items-start gap-6 md:grid-cols-2">
<ProfileForm {...user} nextPath={setup === "1" ? setupNextPath : undefined} />
<EmailSettings email={user.email} verified={user.emailVerified}
callbackCompleted={emailAction === "1" && !error} callbackError={typeof error === "string"} />
<PasswordForm />
{oidcEnabled && <SudlohConnection linked={hasSudloh}
callbackError={sudloh === "error" && typeof error === "string" ? error : undefined} />}
{(!hasSudloh || hasCredential) && <EmailSettings email={user.email} verified={user.emailVerified}
callbackCompleted={emailAction === "1" && !error} callbackError={typeof error === "string" && sudloh !== "error"} />}
{(!hasSudloh || hasCredential) && <PasswordForm />}
{hasSudloh && !hasCredential && <p className="text-sm text-muted-foreground">
จัดการอีเมลและรหัสผ่านของคุณผ่าน Sudloh Account
</p>}
</div>
</main>
</div>;