feat(auth) : let Google-only users add a password

This commit is contained in:
2026-10-12 00:34:43 +07:00 Unverified
parent 839f98aab7
commit e2af59292c
3 changed files with 76 additions and 25 deletions
+7 -5
View File
@@ -1,4 +1,4 @@
import { eq } from "drizzle-orm";
import { eq, sql } from "drizzle-orm";
import { redirect } from "next/navigation";
import { connection } from "next/server";
import { UserRoundIcon } from "lucide-react";
@@ -27,15 +27,17 @@ export default async function ProfilePage({ searchParams }: PageProps<"/profile"
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),
getDb().select({ id: accounts.id, providerId: accounts.providerId })
getDb().select({ id: accounts.id, providerId: accounts.providerId,
hasPassword: sql<boolean>`${accounts.password} is not null` })
.from(accounts).where(eq(accounts.userId, session.user.id)),
]);
const [user] = userRows;
if (!user) redirect("/auth/login?next=%2Fprofile");
const hasCredential = accountRows.some((account) => account.providerId === "credential");
const hasPassword = accountRows.some((account) => account.providerId === "credential" && account.hasPassword);
const googleAccountIds = accountRows.filter((account) => account.providerId === "google")
.map((account) => account.id);
const hasOtherAuthMethod = accountRows.some((account) => account.providerId !== "google");
const hasOtherAuthMethod = accountRows.some((account) => account.providerId !== "google"
&& (account.providerId !== "credential" || account.hasPassword));
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 flex items-center gap-2 font-heading text-3xl font-semibold">
@@ -52,7 +54,7 @@ export default async function ProfilePage({ searchParams }: PageProps<"/profile"
callbackCompleted={emailAction === "1" && !error} callbackError={emailAction === "1" && typeof error === "string"} />
{isGoogleAuthEnabled() && <GoogleAccountSettings googleAccountIds={googleAccountIds}
hasOtherAuthMethod={hasOtherAuthMethod} linkError={googleLinkError === "1"} />}
{hasCredential && <PasswordForm />}
<PasswordForm hasPassword={hasPassword} />
</div>
</main>
</div>;