From d4d7dde1ab2c910bca1d3d9b0ec370b7e937e84b Mon Sep 17 00:00:00 2001 From: enes Date: Tue, 7 Jan 2025 20:40:59 +0100 Subject: [PATCH] fix(mod): redirect on edit if user is not original author --- src/pages/mod/loader.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/pages/mod/loader.ts b/src/pages/mod/loader.ts index d311109..e490e65 100644 --- a/src/pages/mod/loader.ts +++ b/src/pages/mod/loader.ts @@ -26,7 +26,7 @@ import { export const modRouteLoader = (ndkContext: NDKContextType) => - async ({ params }: LoaderFunctionArgs) => { + async ({ params, request }: LoaderFunctionArgs) => { const { naddr } = params if (!naddr) { log(true, LogType.Error, 'Required naddr.') @@ -51,6 +51,14 @@ export const modRouteLoader = const loggedInUserPubkey = (userState?.user?.pubkey as string | undefined) || getFallbackPubkey() + // Check if editing and the user is the original author + // Redirect if NOT + const url = new URL(request.url) + const isEditMode = url.pathname.includes('edit-mod') + if (isEditMode && loggedInUserPubkey !== pubkey) { + return redirect(appRoutes.mods) + } + try { // Set up the filters // Main mod content