Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/app/(app)/[account_id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

import { Metadata } from "next";
import { notFound } from "next/navigation";
import { notFound, redirect } from "next/navigation";
import { OrganizationProfilePage } from "@/app/(app)/[account_id]/OrganizationProfilePage";
import { accountsTable, isOrganizationalAccount } from "@/lib/clients/database";
import { IndividualProfilePage } from "./IndividualProfilePage";
Expand Down Expand Up @@ -41,6 +41,10 @@ export default async function AccountPage({ params, searchParams }: PageProps) {
const { account_id } = await params;
const showWelcome = Object.hasOwn(await searchParams, "welcome");

if (account_id !== account_id.toLowerCase()) {
redirect(`/${account_id.toLowerCase()}`);
}
Comment on lines +44 to +46

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The redirect drops the entire query string. If a newly-registered user with a mixed-case account ID arrives at /${account_id}?welcome (e.g. from the onboarding flow), they is redirected to /${account_id.toLowerCase()} without ?welcome, so the welcome modal never renders.

Suggested change
if (account_id !== account_id.toLowerCase()) {
redirect(`/${account_id.toLowerCase()}`);
}
if (account_id !== account_id.toLowerCase()) {
const resolvedSearchParams = await searchParams;
const qs = new URLSearchParams(
Object.entries(resolvedSearchParams).filter(
(e): e is [string, string] => typeof e[1] === "string"
)
).toString();
redirect(`/${account_id.toLowerCase()}${qs ? `?${qs}` : ""}`);
}


const account = await accountsTable.fetchById(account_id);
if (!account) {
notFound();
Expand Down
5 changes: 3 additions & 2 deletions src/lib/clients/database/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class AccountsTable extends BaseTable {
model = "accounts";

async fetchById(account_id: string): Promise<Account | null> {
account_id = account_id.toLowerCase();
try {
LOGGER.debug(`Trying to fetch account for ID`, {
operation: "AccountsTable.fetchById",
Expand Down Expand Up @@ -62,8 +63,8 @@ export class AccountsTable extends BaseTable {
): Promise<Account[]> {
const accountBatches: Account[] = [];

// Remove duplicates
account_ids = [...new Set(account_ids)];
// Remove duplicates and normalize to lowercase
account_ids = [...new Set(account_ids.map((id) => id.toLowerCase()))];

for (let i = 0; i < account_ids.length; i += batchSize) {
const batch = account_ids.slice(i, i + batchSize);
Expand Down
3 changes: 3 additions & 0 deletions src/lib/clients/database/products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export class ProductsTable extends BaseTable {
products: Product[];
lastEvaluatedKey: any;
}> {
account_id = account_id.toLowerCase();
const result = await this.cachedSend(
new QueryCommand({
TableName: this.table,
Expand Down Expand Up @@ -170,6 +171,8 @@ export class ProductsTable extends BaseTable {
account_id: string,
product_id: string
): Promise<Product | null> {
account_id = account_id.toLowerCase();
product_id = product_id.toLowerCase();
try {
const [result, account] = await Promise.all([
this.cachedSend(
Expand Down
Loading