@@ -370,11 +370,17 @@ class _PlansState extends ConsumerState<Plans> {
370370
371371 Future <void > startInAppPurchaseFlow (Plan plan) async {
372372 context.showLoadingDialog ();
373+ // Mark a payment as in flight so that ConfirmEmail's back-press guard
374+ // (confirm_email.dart) preserves the anonymous account if the user
375+ // backs out before signup completes — same protection Stripe and the
376+ // external paymentRedirect flow already get.
377+ ref.read (paymentSessionProvider.notifier).markRedirectInitiated ();
373378 final payments = ref.read (paymentProvider.notifier);
374379 final result = await payments.startInAppPurchaseFlow (
375380 planId: plan.id,
376381 onSuccess: (purchase) => processPurchase (purchase, plan),
377382 onError: (error) {
383+ ref.read (paymentSessionProvider.notifier).clearRedirect ();
378384 if (! mounted) return ;
379385 context.showSnackBar (error);
380386 appLogger.error ('Error subscribing to plan: $error ' );
@@ -383,6 +389,7 @@ class _PlansState extends ConsumerState<Plans> {
383389 );
384390 if (! mounted) return ;
385391 result.fold ((error) {
392+ ref.read (paymentSessionProvider.notifier).clearRedirect ();
386393 context.hideLoadingDialog ();
387394 context.showSnackBar (error.localizedErrorMessage);
388395 appLogger.error ('Error subscribing to plan: $error ' );
@@ -401,8 +408,9 @@ class _PlansState extends ConsumerState<Plans> {
401408
402409 final appSetting = ref.read (appSettingProvider);
403410 if (appSetting.userLoggedIn) {
404- /// If user logged in and purchase is successful then check user account status
405- /// to reflect new purchase and send user to pro flow
411+ /// Renewal: user is already logged in, so the back-press protection
412+ /// the redirect flag was guarding is no longer relevant.
413+ ref.read (paymentSessionProvider.notifier).clearRedirect ();
406414 userRenewalFlow ();
407415 return ;
408416 }
0 commit comments