apple sign with supabase navigation

Custom Code

Hello everybody,

i have enabled apple sign in with supabase using a custom action and i would like to navigate the user based on if they have created a profile. if it's a new user i would like to navigate them to a page where they can make a profile and if it's an existing user who has already made a profile would be navigated to home page. right now with the current code when testing it i get the apple sign in permission and after approval i don't get navigated anywhere it stays on the sign in page and after i leave the app and re-enter i land on home page (signed in with apple email). Thank you for any help.

import 'dart:convert';

// Set your action name, define your arguments and return parameter,
// and then add the boilerplate code using the green button on the right!

import 'package:sign_in_with_apple/sign_in_with_apple.dart';
import 'package:supabase_flutter/supabase_flutter.dart';

Future<dynamic> appleSignInAction(BuildContext context) async {
  final supabase = Supabase.instance.client;

  final credential = await SignInWithApple.getAppleIDCredential(
    scopes: [
      AppleIDAuthorizationScopes.email,
      AppleIDAuthorizationScopes.fullName,
    ],
  );

  final idToken = credential.identityToken;
  if (idToken == null) {
    throw const AuthException(
      'Could not find ID Token from generated credential.',
    );
  }

  final response = await supabase.auth.signInWithIdToken(
    provider: Provider.apple,
    idToken: idToken,
  );

  // Step 3: Check if the user's profile exists using custom action
  final user = response.user;
  final userId = user?.id;

  if (userId == null) {
    throw const AuthException('No user ID associated with this user.');
  }

  // Here is the custom action you created being used
  final profileExists = await checkIfProfileIdExist(userId);

  // Step 4: Navigate based on the profile existence
  if (profileExists == true) {
    // If the profile exists, navigate to the Home Page
    Navigator.pushReplacementNamed(context, '/homePage');
  } else {
    // If the profile does not exist, navigate to the Complete Profile Page
    Navigator.pushReplacementNamed(context, '/completeProfilePage');
  }

  return response;
}
What have you tried so far?

i have made another custom action to check if the user email exist in the profile table in supabase (meaning they have created a profile and it's not their first time entering the app). i am calling this action in my apple sign in custom action and checking if the email exist then navigate to home page if not navigate to complete profile page.

i have also tried to do it without putting the navigation inside the custom action of the apple sign in. i did it through the flutterflow (see picture) which ended up with the same behavior.

Did you check FlutterFlow's Documentation for this topic?
Yes
2