Skip to content

Commit

Permalink
fix: remove v1 profile suffix from url (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysu authored Nov 13, 2023
1 parent 2394dd5 commit f8e0b9d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/app/u/[namespace]/[localname]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand All @@ -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 });

Expand Down
6 changes: 5 additions & 1 deletion src/utils/handle.ts
Original file line number Diff line number Diff line change
@@ -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);
}

Expand Down

0 comments on commit f8e0b9d

Please sign in to comment.