nayanAubie / signin_with_linkedin

MIT License
0 stars 2 forks source link

onGetUserProfile getting called twice #9

Closed davidberken closed 2 months ago

davidberken commented 2 months ago

It seems like in the SignInWithLinkedIn.signIn() method the onGetUserProfile method is being called twice on a single click of my button. Below is the relevant code maybe I am missing something?

// This is in a column and the method is just an on click for an inherited TextButton
LoadingButton(
  buttonText: "Login with LinkedIn",
  method: () async => await linkedInLogin(),
  width: .362.sw,
  buttonTextStyle: DignifyTheme.robotoButton
)
final _linkedInConfig = LinkedInConfig(
  clientId: _clientID,
  clientSecret: _clientSecret,
  redirectUrl: _redirectURL,
  scope: ['openid', 'profile', 'email']
);
Future<void> linkedInLogin() async {
  try {
    setState(() {
      isProcessing = true;
    });

    await SignInWithLinkedIn.signIn(
      context,
      config: _linkedInConfig,
      onGetUserProfile: (token, user) async {
        // This gets hit twice with a breakpoint after clicking the "LoadingButton" widget
        if (token.accessToken == null) {
          if (mounted) {
            setState(() {
              isProcessing = false;
            });

            toastError("Could not obtain login information. Please try again.", context);
          }
        } else {
          debugPrint(token.accessToken!.toString());
          LoginResponse loginResponse = await UserRequests.ssoLogin(provider: "linkedin-openid", token: token.accessToken!);
          await handleLoginResponse(loginResponse: loginResponse);
        }
      },
      onSignInError: (error) {
        throw Exception(error);
      }
    );
  } catch (error) {
    debugPrint(error.toString());
    if (mounted) {
      setState(() {
        isProcessing = false;
      });
      toastError("Something went wrong. Please try again.", context);
    }
  }
}
davidberken commented 2 months ago

Just an update... I tried removing any setStates in my method and before the SignInWithLinkedIn.signIn method with no luck. I ended up just adding a boolean to set when it hits it the first time to make sure it doesnt run the code twice but any additional help or feedback would be appreciated!

nayanAubie commented 2 months ago

Yes @davidberken It is calling twice, I am checking the cause. thanks.