MaikuB / flutter_appauth

A Flutter wrapper for AppAuth iOS and Android SDKs
270 stars 243 forks source link

PlatformException(authorize_failed, Concurrent operations detected: authorize, authorize, null, null) #352

Closed ANMichelini closed 1 year ago

ANMichelini commented 2 years ago

I'm using AppAuth library to authenticate the user, but when i try to do it i get this error:

PlatformException(authorize_failed, Concurrent operations detected: authorize, authorize, null, null).

It only works running the app with the command flutter run, but it doesn't work running it with VSC.

This is my code:

import 'package:flutter/material.dart';
import 'package:flutter_appauth/flutter_appauth.dart';
import 'package:get/get.dart';

class LoginController extends GetxController {
  final GlobalKey<FormState> formKey = GlobalKey<FormState>();

  FlutterAppAuth appAuth = const FlutterAppAuth();
  // FirebaseAuth firebaseAuth = FirebaseAuth.instance;

  Future<AuthorizationResponse?> login() async {
    try {
      final AuthorizationResponse? response = await appAuth.authorize(
        AuthorizationRequest(
          '454399',
          'com.example:://callback',
          serviceConfiguration: const AuthorizationServiceConfiguration(
            authorizationEndpoint:
                'example',
            tokenEndpoint: 'example',
            endSessionEndpoint: 'example',
          ),
        ),
      );
      print('RESPONSE ==> $response');
      // await Hive.box<AuthorizationTokenResponse>(BoxKeys.appKey)
      //     .put(DataKeys.userKey, response!);
    } catch (e) {
      print('ERROR ====> $e');
      Get.snackbar('Error de login', 'Ocurrió un error al iniciar sesión');
    }
    return null;
  }
}
MaikuB commented 1 year ago

Missed responding to this but the error mentions why this occurs so you need to ensure that your app doesn't do concurrent operations. Furthermore, this problem wouldn't be one that depends on if you use the CLI or IDE