From d9f68bb1139b471210c8e6135cb5508bc299a83c Mon Sep 17 00:00:00 2001 From: Guillaume Date: Thu, 18 Jul 2024 16:03:58 +0200 Subject: [PATCH] Fix cloud buy button not showing when logged out --- components/plans.tsx | 65 +++++++++++++++++++++++++++----------------- utils/auth.tsx | 3 ++ 2 files changed, 43 insertions(+), 25 deletions(-) diff --git a/components/plans.tsx b/components/plans.tsx index d629da3c..ab2d5041 100644 --- a/components/plans.tsx +++ b/components/plans.tsx @@ -100,31 +100,46 @@ const PlansView: FunctionComponent<{ const subscribeBtn = (plan: Plans) => ( <> - - {currentUser.data?.plan === 'FREE' && ( -
- {pricing[plan].trialDays} days free trial included -
- )} +
+ +
+ <> + {/* Hide trial if already subscribed */} + {(!currentUser.data || currentUser.data?.plan === 'FREE') && ( +
+ {pricing[plan].trialDays} days free trial included +
+ )} + ); const tickBadge = ( diff --git a/utils/auth.tsx b/utils/auth.tsx index ee921f0b..806e3807 100644 --- a/utils/auth.tsx +++ b/utils/auth.tsx @@ -1,3 +1,4 @@ +import { useQueryClient } from '@tanstack/react-query'; import { EmailAuthProvider, GoogleAuthProvider, @@ -14,6 +15,7 @@ import { import { useEffect, useState } from 'react'; const useAuth = () => { + const queryClient = useQueryClient(); // user is set when user is authenticated but email is not necessarily verified const [user, setUser] = useState(null); // is auth set when user is authenticated and email is verified @@ -25,6 +27,7 @@ const useAuth = () => { const logout = async () => { await auth.signOut(); + queryClient.invalidateQueries({ queryKey: ['currentUser'] }); }; const getIdToken = async (force = false) => {