handleTokenChanges method

Future<void> handleTokenChanges(
  1. User? fbUser
)

Implementation

Future<void> handleTokenChanges(fb_auth.User? fbUser) async {
  logd('handleTokenChanges called');

  // Call the function to get the cookie set
  // final token = await _fbAuth.currentUser!.getIdToken();
  if (fbUser == null) {
    logd('fbUser is null during handleTokenChanges');
    return;
  } else {
    logd('fbUser is NOT null during handleTokenChanges');
    //TODO: added this here but not sure it needs to do this again...
    // await refreshCurrentUser();

    // Note: FCM token management has been moved to NotificationService.
    // Apps should subscribe to isLoggedInStream and call
    // NotificationService.initializeFcmToken() when user logs in.
  }

  //
  // Set the cookie for multi-domain auth
  //
  if (AppConfigBase.doUseBackendEmulator == false &&
      AppConfigBase.useCookieFederatedAuth == true) {
    final url = RepoHelpers.getFunctionUrl(_fbAuth.app, 'authfunctions-onsignin');
    final token = await fbUser.getIdToken();

    logd('onSignIn url: $url');
    // logd('token: $token');

    final http.Client client = http.Client();
    //TODO: temp disabled
    // if (client is BrowserClient) {
    //   client.withCredentials = true;
    // }

    final response = await client.post(Uri.parse(url), body: {
      // 'Accept': '*/*',
      // 'User-Agent': 'Thunder Client (https://www.thunderclient.com)',
      // 'Authorization': 'Bearer $token',
      'token': token,
    });

    if (response.statusCode == 200) {
      logd('Cookie set successfully!!');
    } else {
      loge('Failed to set cookie!!');
    }
  }
}