From 078f2c7e6c3711862c622d561660627750bbea98 Mon Sep 17 00:00:00 2001 From: Maximilian Harz Date: Thu, 4 Dec 2025 10:04:19 +0100 Subject: [PATCH] Remove invalid inviteCodes from localStorage; don't get stuck when validating --- lib/src/Components/Map/hooks/useMyProfile.ts | 6 +++--- lib/src/Components/Onboarding/InvitePage.tsx | 14 +++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/src/Components/Map/hooks/useMyProfile.ts b/lib/src/Components/Map/hooks/useMyProfile.ts index 27f50fbf..04799152 100644 --- a/lib/src/Components/Map/hooks/useMyProfile.ts +++ b/lib/src/Components/Map/hooks/useMyProfile.ts @@ -14,10 +14,10 @@ export const useMyProfile = () => { (item) => item.layer?.userProfileLayer && item.user_created?.id === user?.id, ) - const isAnyUserProfileLoaded = !!items.find((item) => item.layer?.userProfileLayer) + const isUserProfileLayerLoaded = !!items.find((item) => item.layer?.userProfileLayer) // allItemsLoaded is not reliable - const isMyProfileLoaded = isAnyUserProfileLoaded && !!user + const isMyProfileLoaded = isUserProfileLayerLoaded && !!user const createEmptyProfile = async () => { if (!user) return @@ -45,5 +45,5 @@ export const useMyProfile = () => { return result } - return { myProfile, isMyProfileLoaded, createEmptyProfile } + return { myProfile, isMyProfileLoaded, isUserProfileLayerLoaded, createEmptyProfile } } diff --git a/lib/src/Components/Onboarding/InvitePage.tsx b/lib/src/Components/Onboarding/InvitePage.tsx index 7b54a23a..d0e55ff4 100644 --- a/lib/src/Components/Onboarding/InvitePage.tsx +++ b/lib/src/Components/Onboarding/InvitePage.tsx @@ -25,7 +25,7 @@ export function InvitePage({ inviteApi, itemsApi }: Props) { const navigate = useNavigate() const updateItem = useUpdateItem() - const { myProfile, isMyProfileLoaded, createEmptyProfile } = useMyProfile() + const { myProfile, isUserProfileLayerLoaded, createEmptyProfile } = useMyProfile() if (!id) throw new Error('Invite ID is required') @@ -50,7 +50,7 @@ export function InvitePage({ inviteApi, itemsApi }: Props) { const confirmFollowAsync = async () => { if (!isAuthenticated) return - if (!isMyProfileLoaded || isRedeemingDone) return + if (!isUserProfileLayerLoaded || isRedeemingDone) return const myActualProfile = myProfile ?? (await createEmptyProfile()) @@ -92,6 +92,7 @@ export function InvitePage({ inviteApi, itemsApi }: Props) { if (!invitingProfileId) { toast.error('Invalid invite code') + localStorage.removeItem('inviteCode') navigate('/') return } @@ -100,6 +101,7 @@ export function InvitePage({ inviteApi, itemsApi }: Props) { if (invitingProfileId === myProfile?.id) { toast.error('You cannot invite yourself') + localStorage.removeItem('inviteCode') // Navigate to own profile navigate('/item/' + myProfile.id) return @@ -111,12 +113,14 @@ export function InvitePage({ inviteApi, itemsApi }: Props) { ) ) { toast.error('You are already following this profile') + localStorage.removeItem('inviteCode') navigate('/item/' + invitingProfileId) return } if (!invitingProfile) { toast.error('Inviting profile not found') + localStorage.removeItem('inviteCode') navigate('/') return } @@ -135,10 +139,10 @@ export function InvitePage({ inviteApi, itemsApi }: Props) { localStorage.setItem('inviteCode', id) } - if (!isMyProfileLoaded) return + if (!isUserProfileLayerLoaded) return - void validateInvite(id) setValidationDone(true) + void validateInvite(id) }, [ id, isAuthenticated, @@ -146,11 +150,11 @@ export function InvitePage({ inviteApi, itemsApi }: Props) { navigate, isAuthenticationInitialized, myProfile, - isMyProfileLoaded, itemsApi, isRedeemingDone, isValidationDone, createEmptyProfile, + isUserProfileLayerLoaded, ]) const goToSignup = () => {