diff --git a/components/ProfilePage/ProfilePage.js b/components/ProfilePage/ProfilePage.js index 4f1c4b52..c045a385 100644 --- a/components/ProfilePage/ProfilePage.js +++ b/components/ProfilePage/ProfilePage.js @@ -88,13 +88,16 @@ function ProfilePage({ id, slug }) { // const router = useRouter(); const latestSlug = data?.GetUser?.slug; // slug may update after user edits + const userId = currentUser?.id; useEffect(() => { - if (!latestSlug) return; - const targetPath = `/user/${encodeURI(latestSlug)}`; - if (window.location.pathname !== targetPath) { + if (latestSlug === undefined) return; + const targetPath = latestSlug + ? `/user/${encodeURI(latestSlug)}` + : `/user?id=${userId}`; + if (router.asPath !== targetPath) { router.replace(targetPath); } - }, [latestSlug, router]); + }, [latestSlug, userId, router]); if (loading) { return (