From f85ce81e30d91ef41e426c8dd47a614c5117bd32 Mon Sep 17 00:00:00 2001 From: Maximilian Harz Date: Thu, 4 Dec 2025 00:42:12 +0100 Subject: [PATCH] Show errors when trying to redeem invites by yourself or by profiles you are already following --- lib/src/Components/Onboarding/InvitePage.tsx | 23 +++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/src/Components/Onboarding/InvitePage.tsx b/lib/src/Components/Onboarding/InvitePage.tsx index 0f67242a..f4996a54 100644 --- a/lib/src/Components/Onboarding/InvitePage.tsx +++ b/lib/src/Components/Onboarding/InvitePage.tsx @@ -72,22 +72,36 @@ export function InvitePage({ inviteApi, itemsApi }: Props) { if (!invitingProfileId) { toast.error('Invalid invite code') - setValidationDone(true) navigate('/') return } const invitingProfile = await itemsApi.getItem(invitingProfileId) + if (invitingProfileId === myProfile?.id) { + toast.error('You cannot invite yourself') + // Navigate to own profile + navigate('/item/' + myProfile.id) + return + } + + if ( + myProfile?.relations?.some( + (r) => r.type === 'is_following' && r.related_items_id === invitingProfileId, + ) + ) { + toast.error('You are already following this profile') + navigate('/item/' + invitingProfileId) + return + } + if (!invitingProfile) { toast.error('Inviting profile not found') - setValidationDone(true) navigate('/') return } setInvitingProfile(invitingProfile) - setValidationDone(true) } if (!id) throw new Error('Invite ID is required') @@ -101,7 +115,10 @@ export function InvitePage({ inviteApi, itemsApi }: Props) { localStorage.setItem('inviteCode', id) } + if (!isMyProfileLoaded) return + void validateInvite(id) + setValidationDone(true) }, [ id, isAuthenticated,