#[SOLVED] Auth flutter

40 messages · Page 1 of 1 (latest)

digital fern
#

What exactly is your code and the error?

outer nebula
#

I already solved it, now I have a question, how do I verify the email so that a modal appears and there they can enter the code and it is automatically verified?

#

Can you give me an example to guide me?

digital fern
outer nebula
#

What would be the easiest and most effective solution?

digital fern
outer nebula
#

I have this error when implementing the auth google and facebook

dark maple
outer nebula
#

Now if you register but there is a detail that remains on the verification page so you are already registered and appwrite me if the registered account appears but in the app an error appears when logging in with Google

outer nebula
#

the error that appears is an error in the credentials but I made sure that they are correct here are parts of the code

#

Future<bool> loginWithOAuth(String provider) async {
try {
await account.createOAuth2Session(
provider: provider,
success: "appwrite-callback-[]://cloud.appwrite.io/v1/auth/oauth2/success",
failure: "appwrite-callback-[
]://cloud.appwrite.io/v1/auth/oauth2/failure",
);
_updateAuthStatus();
return true;
} catch (e) {
if (e is AppwriteException) {
print('Error al iniciar sesión con OAuth:');
print('Mensaje: ${e.message}');
print('Código: ${e.code}');
print('Tipo: ${e.type}');
} else {
print('Excepción no reconocida:');
print(e);
}
return false;
}
}

SignInButton.mini(
buttonType: ButtonType.google,
onPressed: () async {
// Obtén la instancia de AuthenticationService utilizando Provider
AuthenticationService authService = Provider.of<AuthenticationService>(context, listen: false);

            // Lógica para iniciar sesión con Google
            bool success = await authService.loginWithOAuth('google');
            if (success) {
              print('Inicio de sesión con Google exitoso');

              // Cambiar el índice de la página a 0 (Inicio)
              Provider.of<PageProvider>(context, listen: false).changePage(0);

              // Cerrar la ventana de inicio de sesión
              Navigator.pop(context);
            } else {
              print('Inicio de sesión con Google fallido');
              ScaffoldMessenger.of(context).showSnackBar(
                SnackBar(
                  content: Text('Error al iniciar sesión con Google. Por favor, inténtalo de nuevo.'),
                ),
              );
            }
          },
        ),
digital fern
digital fern
digital fern
outer nebula
#

And how could I do it because if eh replaced the correct id and key of Google cosola and I realize that in appwrite if you register but the app does not log in I think I have an error in my code I am in flutter.

digital fern
outer nebula
#

I mean that appwrite if the user is saved, but in the app it does not receive the credentials

digital fern
outer nebula
#

If it redirects me but does not validate the credentials, an error appears when starting with Google.

digital fern
#

maybe you can share a recording of what's going wrong?

outer nebula
digital fern
# outer nebula

what's your updated code including _updateAuthStatus()? Please make sure to format the code using 3 back ticks.

#

please also share your logs because the screen recording doesn't show the output of

      if (e is AppwriteException) {
        print('Error al iniciar sesión con OAuth:');
        print('Mensaje: ${e.message}');
        print('Código: ${e.code}');
        print('Tipo: ${e.type}');
      } else {
        print('Excepción no reconocida:');
        print(e);
      }
outer nebula
#

I/flutter ( 9414): Error al iniciar sesión con OAuth:
I/flutter ( 9414): Mensaje: Invalid OAuth2 Response. Key and Secret not available.
I/flutter ( 9414): Código: 500
I/flutter ( 9414): Tipo: null
I/flutter ( 9414): Inicio de sesión con Google fallido

carmine marlin
#

What is the code in _updateAuthStatus()?

outer nebula
#

Stream<bool> isAuthenticated() {
_updateAuthStatus();
return _authController.stream;
}

void _updateAuthStatus() async {
bool isAuthenticated = await _checkAuthenticated();
_authController.add(isAuthenticated);
}

carmine marlin
#

Okay and what's inside _checkAuthenticated()

outer nebula
#

With email and password the login works correctly, but with Google I don't want appwrite if the name, email and verification are registered normally but it doesn't log in.

#

Future<bool> _checkAuthenticated() async {
try {
await account.get();
return true;
} catch (e) {
print(e);
return false;
}
}

carmine marlin
#

Did you remove the success and failure fields?

outer nebula
#

Enough already and apparently if you log in but the black screen stays, I close it and turn it on, it opens and validates that if you log in, it takes me home. But I don't know how to fix the black screen

#

Future<bool> loginWithOAuth(String provider) async {
try {
final session = await account.createOAuth2Session(provider: provider);
_updateAuthStatus();
return true;
} catch (e) {
if (e is AppwriteException) {
print('Error al iniciar sesión con OAuth:');
print('Mensaje: ${e.message}');
print('Código: ${e.code}');
print('Tipo: ${e.type}');
} else {
print('Excepción no reconocida:');
print(e);
}
return false;
}
}

digital fern
digital fern
outer nebula
#

already solved. I have another question, is it possible to use the login with google natively or only through the web?