fix: persist selected plan through Google OAuth reloads
This commit is contained in:
parent
b366d17a05
commit
0ab94f88c9
2 changed files with 8 additions and 1 deletions
|
|
@ -94,8 +94,12 @@ const AppContent: React.FC = () => {
|
||||||
setIsModalOpen(false);
|
setIsModalOpen(false);
|
||||||
await refreshProfile();
|
await refreshProfile();
|
||||||
|
|
||||||
|
// Recupera a intenção de plano caso tenha recarregado a página (ex: Login via Google)
|
||||||
|
const savedPlan = localStorage.getItem('intended_plan');
|
||||||
|
const finalPlan = selectedPlan === 'monthly' ? 'monthly' : savedPlan;
|
||||||
|
|
||||||
// Se acabou de fazer o cadastro clicando em um plano pago (monthly), leva direto pro Stripe!
|
// Se acabou de fazer o cadastro clicando em um plano pago (monthly), leva direto pro Stripe!
|
||||||
if (authMode === 'register' && selectedPlan === 'monthly') {
|
if ((authMode === 'register' || isCompletingProfile) && finalPlan === 'monthly') {
|
||||||
try {
|
try {
|
||||||
const { data: { session } } = await supabase.auth.getSession();
|
const { data: { session } } = await supabase.auth.getSession();
|
||||||
if (session) {
|
if (session) {
|
||||||
|
|
@ -109,6 +113,7 @@ const AppContent: React.FC = () => {
|
||||||
});
|
});
|
||||||
const { url, error } = await res.json();
|
const { url, error } = await res.json();
|
||||||
if (!error && url) {
|
if (!error && url) {
|
||||||
|
localStorage.removeItem('intended_plan');
|
||||||
window.location.href = url; // Redireciona pro Checkout
|
window.location.href = url; // Redireciona pro Checkout
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -120,6 +125,7 @@ const AppContent: React.FC = () => {
|
||||||
|
|
||||||
// Login intent logic handled inside context or simply by state update
|
// Login intent logic handled inside context or simply by state update
|
||||||
localStorage.removeItem('login_intent');
|
localStorage.removeItem('login_intent');
|
||||||
|
localStorage.removeItem('intended_plan');
|
||||||
};
|
};
|
||||||
|
|
||||||
// Helper function for navigating with real URLs
|
// Helper function for navigating with real URLs
|
||||||
|
|
|
||||||
|
|
@ -99,6 +99,7 @@ const RegistrationModal: React.FC<RegistrationModalProps> = ({
|
||||||
|
|
||||||
const handleGoogleLogin = async () => {
|
const handleGoogleLogin = async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
localStorage.setItem('intended_plan', plan); // Salva o plano na memória antes de sair
|
||||||
const { error } = await supabase.auth.signInWithOAuth({
|
const { error } = await supabase.auth.signInWithOAuth({
|
||||||
provider: 'google',
|
provider: 'google',
|
||||||
options: {
|
options: {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue