Skip to content

Commit 85c0a2e

Browse files
committed
address referrer review follow-up
1 parent 6753e2a commit 85c0a2e

8 files changed

Lines changed: 24 additions & 20 deletions

File tree

src/app/auth/callback/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createClient } from "@/utils/supabase/server";
2-
import { appendSuccessParam, normalizeNextPath } from "@/utils/authRedirects";
2+
import { appendSuccessParam, normaliseNextPath } from "@/utils/authRedirects";
33
import { NextResponse } from "next/server";
44

55
const isAuthDebugEnabled = process.env.NEXT_PUBLIC_AUTH_DEBUG === "true";
@@ -23,7 +23,7 @@ export async function GET(request: Request) {
2323
const requestedNextPath =
2424
requestUrl.searchParams.get("next") ??
2525
requestUrl.searchParams.get("redirect_to");
26-
const nextPath = normalizeNextPath(requestedNextPath, "/profile");
26+
const nextPath = normaliseNextPath(requestedNextPath, "/profile");
2727

2828
if (code) {
2929
const supabase = await createClient();

src/app/auth/confirm/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
appendSuccessParam,
44
getDefaultNextPathByType,
55
isSupportedEmailAuthType,
6-
normalizeNextPath,
6+
normaliseNextPath,
77
} from "@/utils/authRedirects";
88
import { NextResponse } from "next/server";
99

@@ -35,7 +35,7 @@ export async function GET(request: Request) {
3535
requestUrl.searchParams.get("next") ??
3636
requestUrl.searchParams.get("redirect_to");
3737
const defaultNextPath = getDefaultNextPathByType(authType);
38-
const nextPath = normalizeNextPath(requestedNextPath, defaultNextPath);
38+
const nextPath = normaliseNextPath(requestedNextPath, defaultNextPath);
3939

4040
if (!tokenHash || !isSupportedEmailAuthType(authType)) {
4141
debugAuth("invalid-confirm-query", {

src/app/auth/session/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
appendSuccessParam,
44
getDefaultNextPathByType,
55
isSupportedEmailAuthType,
6-
normalizeNextPath,
6+
normaliseNextPath,
77
} from "@/utils/authRedirects";
88
import { NextResponse } from "next/server";
99

@@ -54,7 +54,7 @@ export async function POST(request: Request) {
5454
}
5555

5656
const defaultNextPath = getDefaultNextPathByType(type);
57-
const nextPath = normalizeNextPath(
57+
const nextPath = normaliseNextPath(
5858
typeof body?.next === "string" ? body.next : null,
5959
defaultNextPath
6060
);

src/components/AuthHashCompletion.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useEffect } from "react";
44
import {
55
getDefaultNextPathByType,
66
isSupportedEmailAuthType,
7-
normalizeNextPath,
7+
normaliseNextPath,
88
} from "@/utils/authRedirects";
99

1010
const INVALID_LINK_MESSAGE =
@@ -37,7 +37,7 @@ export default function AuthHashCompletion() {
3737
queryParams.get("next") ?? queryParams.get("redirect_to");
3838
const requestedType = queryParams.get("type") ?? hashType;
3939
const defaultNextPath = getDefaultNextPathByType(requestedType);
40-
const nextPath = normalizeNextPath(preferredNextPath, defaultNextPath);
40+
const nextPath = normaliseNextPath(preferredNextPath, defaultNextPath);
4141

4242
const authCode = queryParams.get("code");
4343
const hasAuthHashPayload =
@@ -126,7 +126,7 @@ export default function AuthHashCompletion() {
126126
return;
127127
}
128128

129-
const typedNextPath = normalizeNextPath(
129+
const typedNextPath = normaliseNextPath(
130130
preferredNextPath,
131131
getDefaultNextPathByType(type)
132132
);
@@ -177,7 +177,7 @@ export default function AuthHashCompletion() {
177177
return;
178178
}
179179

180-
const resolvedNextPath = normalizeNextPath(data.next, typedNextPath);
180+
const resolvedNextPath = normaliseNextPath(data.next, typedNextPath);
181181
debugAuth("session-finalized", {
182182
type,
183183
nextPath: resolvedNextPath,

src/utils/attributionUtils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ const getCookie = (name: string): string | null => {
4848

4949
if (!value) return null;
5050

51-
return normaliseReferrer(value) ?? null;
51+
const cleanedValue = normaliseReferrer(value);
52+
53+
if (!cleanedValue.trim()) return null;
54+
55+
return cleanedValue;
5256
};
5357

5458
const getExternalDocumentReferrer = (): string | null => {

src/utils/authRedirects.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const getDefaultNextPathByType = (type: string | null | undefined) => {
2424
return "/profile";
2525
};
2626

27-
export const normalizeNextPath = (
27+
export const normaliseNextPath = (
2828
candidatePath: string | null | undefined,
2929
fallbackPath: string
3030
) => {
@@ -49,8 +49,8 @@ export const normalizeNextPath = (
4949
};
5050

5151
export const appendSuccessParam = (path: string, successValue: string) => {
52-
const normalizedPath = normalizeNextPath(path, "/profile");
53-
const url = new URL(normalizedPath, "https://www.peels.app");
52+
const normalisedPath = normaliseNextPath(path, "/profile");
53+
const url = new URL(normalisedPath, "https://www.peels.app");
5454
url.searchParams.set("success", successValue);
5555
return `${url.pathname}${url.search}${url.hash}`;
5656
};

src/utils/referrer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ export function normaliseReferrer(referrer: string | undefined) {
2626
}
2727

2828
export function getSafeHttpReferrer(referrer: string | undefined) {
29-
const normalisedReferrer = normaliseReferrer(referrer)?.trim();
29+
const cleanedReferrer = normaliseReferrer(referrer)?.trim();
3030

31-
if (!normalisedReferrer) return undefined;
31+
if (!cleanedReferrer) return undefined;
3232

3333
try {
34-
const referrerUrl = new URL(normalisedReferrer);
34+
const referrerUrl = new URL(cleanedReferrer);
3535

3636
if (!["http:", "https:"].includes(referrerUrl.protocol)) {
3737
return undefined;

src/utils/storage.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const PRODUCTION_SUPABASE_HOST = "mfnaqdyunuafbwukbbyr.supabase.co";
22
const STORAGE_PUBLIC_PATH = "/storage/v1/object/public";
33

4-
function normalizeAssetPath(assetPath: string) {
4+
function normaliseAssetPath(assetPath: string) {
55
return assetPath.replace(/^\/+/, "");
66
}
77

@@ -22,7 +22,7 @@ export function getStoragePublicUrl(bucket: string, assetPath: string) {
2222

2323
if (!supabaseUrl) return null;
2424

25-
return `${supabaseUrl.replace(/\/$/, "")}${STORAGE_PUBLIC_PATH}/${bucket}/${normalizeAssetPath(assetPath)}`;
25+
return `${supabaseUrl.replace(/\/$/, "")}${STORAGE_PUBLIC_PATH}/${bucket}/${normaliseAssetPath(assetPath)}`;
2626
}
2727

2828
export function usesHostedStaticAssets() {
@@ -43,7 +43,7 @@ export function getStaticAssetUrl(
4343
export function getStaticFontUrl(assetPath: string) {
4444
return getStoragePublicUrl(
4545
"static",
46-
`fonts/${normalizeAssetPath(assetPath)}`
46+
`fonts/${normaliseAssetPath(assetPath)}`
4747
);
4848
}
4949

0 commit comments

Comments
 (0)