From 1971ff370612093d72bafff80bb8b3bea370167f Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Fri, 6 Dec 2024 14:30:52 -0300 Subject: [PATCH] fix choose-username flow --- .../hub/src/app/settings/choose-username/ChooseUsername.tsx | 3 ++- packages/hub/src/app/settings/choose-username/page.tsx | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/hub/src/app/settings/choose-username/ChooseUsername.tsx b/packages/hub/src/app/settings/choose-username/ChooseUsername.tsx index 08c8b7fb83..fa6b349293 100644 --- a/packages/hub/src/app/settings/choose-username/ChooseUsername.tsx +++ b/packages/hub/src/app/settings/choose-username/ChooseUsername.tsx @@ -22,7 +22,8 @@ export const ChooseUsername: FC = () => { >({ action: setUsernameAction, onSuccess: () => { - router.replace("/"); + // this is enough - `page.tsx` will notice that the username is set now, and redirect to the home page + router.refresh(); }, formDataToInput: (data) => ({ username: data.username }), blockOnSuccess: true, diff --git a/packages/hub/src/app/settings/choose-username/page.tsx b/packages/hub/src/app/settings/choose-username/page.tsx index 54359fa4a4..9d8b2b930e 100644 --- a/packages/hub/src/app/settings/choose-username/page.tsx +++ b/packages/hub/src/app/settings/choose-username/page.tsx @@ -1,13 +1,13 @@ import { Metadata } from "next"; import { redirect } from "next/navigation"; -import { getSessionUserOrRedirect } from "@/users/auth"; +import { auth } from "@/lib/server/auth"; import { ChooseUsername } from "./ChooseUsername"; export default async function OuterChooseUsernamePage() { - const sessionUser = await getSessionUserOrRedirect(); - if (sessionUser.username) { + const session = await auth(); + if (!session?.user.email || session.user.username) { redirect("/"); }