From b3ff10a935f384c03b2cc3d81da901827e6e2445 Mon Sep 17 00:00:00 2001 From: Kris Urbas Date: Mon, 13 Nov 2023 10:54:54 +0100 Subject: [PATCH] fix: remove v1 profile suffix from url --- src/app/u/[namespace]/[localname]/page.tsx | 9 +++++++-- src/utils/handle.ts | 6 +++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/app/u/[namespace]/[localname]/page.tsx b/src/app/u/[namespace]/[localname]/page.tsx index e766583..6a612f2 100644 --- a/src/app/u/[namespace]/[localname]/page.tsx +++ b/src/app/u/[namespace]/[localname]/page.tsx @@ -2,7 +2,7 @@ import { ProfileFragment } from "@lens-protocol/client"; import { never } from "@lens-protocol/shared-kernel"; import truncateMarkdown from "markdown-truncate"; import { ResolvingMetadata } from "next"; -import { notFound } from "next/navigation"; +import { notFound, redirect } from "next/navigation"; import { client } from "@/app/client"; import { SearchParams } from "@/app/types"; @@ -11,7 +11,7 @@ import { twitterHandle } from "@/config"; import { AppManifest, findApp, findFavoriteApp, findProfileApps } from "@/data"; import { formatProfileHandle } from "@/formatters"; import { resolvePlatformType } from "@/utils/device"; -import { getFullHandle } from "@/utils/handle"; +import { getFullHandle, hasV1Suffix, removeV1Suffix } from "@/utils/handle"; import { resolveAttribution } from "@/utils/request"; import { openWith } from "./actions"; @@ -27,6 +27,11 @@ export type ProfilePageProps = { export default async function ProfilePage({ params, searchParams }: ProfilePageProps) { const platform = resolvePlatformType(); + + if (hasV1Suffix(params.localname)) { + redirect(`/u/${params.namespace}/${removeV1Suffix(params.localname)}`); + } + const fullHandle = getFullHandle(params.namespace, params.localname); const profile = await client.profile.fetch({ forHandle: fullHandle }); diff --git a/src/utils/handle.ts b/src/utils/handle.ts index 452d5ed..61fd170 100644 --- a/src/utils/handle.ts +++ b/src/utils/handle.ts @@ -1,7 +1,11 @@ const V1_SUFFIX = ".lens"; +export function hasV1Suffix(handle: string): boolean { + return handle.endsWith(V1_SUFFIX); +} + export function removeV1Suffix(handle: string): string { - if (handle.endsWith(".lens")) { + if (hasV1Suffix(handle)) { return handle.slice(0, -V1_SUFFIX.length); }