#[SOLVED] Auth flutter
40 messages · Page 1 of 1 (latest)
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?
Appwrite's built in email verification uses a link that the user clicks/taps. You would need to set up deep linking so that the user is routed into your app where you can grab the secret and make the 2nd API call.
Otherwise, you can manually handle email verification by using a custom collection for the codes and appwrite functions to start and finish the verification.
What would be the easiest and most effective solution?
use appwrite's built in email verification system and set up deep linking
I have this error when implementing the auth google and facebook
Hello, that means you didn't have setup properly the Google oAuth flow.
You will need to go to the Google Cloud console and set the redirect URLs and in the Appwrite dashboard the AppID and App secret (secreto de App, creo que aparece en español)
Here you have a complete tutorial with all steps needed: https://medium.com/@wendell.malpas/a-step-by-step-guide-enabling-google-oauth-2-0-on-android-and-appwrite-1be94e7a09a3
OAuth 2.0 is a widely used authorization framework that allows applications to access user data from various platforms, including Google…
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
What's such error? The same?
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.'),
),
);
}
},
),
FYI, it's best to wrap code in backticks to format a bit nicer. You can use 1 backtick for inline code (https://www.markdownguide.org/basic-syntax/#code) and 3 backticks for multiline code (https://www.markdownguide.org/extended-syntax/#syntax-highlighting.
credentials means the OAuth2 client ID you set in Appwrite compared to the one created in GOogle
btw, for mobile, it's best to not set success and failure
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.
Sorry I don't quite understand you
I mean that appwrite if the user is saved, but in the app it does not receive the credentials
do you mean you're not redirected back into the app?
If it redirects me but does not validate the credentials, an error appears when starting with Google.
sprry i don't understand
maybe you can share a recording of what's going wrong?
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);
}
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
What is the code in _updateAuthStatus()?
Stream<bool> isAuthenticated() {
_updateAuthStatus();
return _authController.stream;
}
void _updateAuthStatus() async {
bool isAuthenticated = await _checkAuthenticated();
_authController.add(isAuthenticated);
}
Okay and what's inside _checkAuthenticated()
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;
}
}
Did you remove the success and failure fields?
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;
}
}
looks like your oauth2 failed for some reason...
Please make sure to use 3 backticks for multiline code (https://www.markdownguide.org/extended-syntax/#syntax-highlighting.
on your computer, browse to https://cloud.appwrite.io/v1/account/sessions/oauth2/google?project=<your project id> and try to log in
already solved. I have another question, is it possible to use the login with google natively or only through the web?
Only through web