Redirect to the proper player page URL when appropriate

This commit is contained in:
Alec LaLonde
2021-03-02 12:11:49 -07:00
parent 3e249faf93
commit 20b5035987

View File

@@ -180,12 +180,27 @@ export const getStaticPaths: GetStaticPaths<QueryParams> = async () => {
export const getStaticProps = async (
context: GetStaticPropsContext<QueryParams>,
) => {
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 {