From 20b50359876bc51190e7ee9692e0c07ddbdb1a64 Mon Sep 17 00:00:00 2001 From: Alec LaLonde Date: Tue, 2 Mar 2021 12:11:49 -0700 Subject: [PATCH] Redirect to the proper player page URL when appropriate --- packages/web/pages/player/[username].tsx | 27 ++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/packages/web/pages/player/[username].tsx b/packages/web/pages/player/[username].tsx index 9451e108..d0d21e94 100644 --- a/packages/web/pages/player/[username].tsx +++ b/packages/web/pages/player/[username].tsx @@ -180,12 +180,27 @@ export const getStaticPaths: GetStaticPaths = async () => { export const getStaticProps = async ( context: GetStaticPropsContext, ) => { - const username = context.params?.username?.toLowerCase(); - // usernames in the DB are lowercase. This essentially - // makes this page's router variable case-insensitive. - let player = null; - if (username != null) { - player = await getPlayer(username?.toLowerCase()); + const username = context.params?.username; + if (username == null) { + return { + redirect: { + desination: '/', + permanent: false + } + } + } + + let player = await getPlayer(username); + if (player == null) { + player = await getPlayer(username.toLowerCase()); + if (player != null) { + return { + redirect: { + destination: `/player/${username.toLowerCase()}`, + permanent: false + } + } + } } return {