What I Wanted- I am making an app where I have a button "Signin with google" where clicking on it will redirect me to google account page and select and account there. When it is successful it will navigate to BoardWindow.
What happens- When I click on the "Sign in with google button" it redirects me to google account page. When I select an account it shows appwrite logo then again goes to google account page. And this loop keeps repeating.
Code-
@override
void initState() {
super.initState();
checkLoginStatus();
}
Future<void> checkLoginStatus() async {
if (await isLoggedIn()) {
print('logged in');
WidgetsBinding.instance.addPostFrameCallback((_) {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => BoardWindow(account: account),
),
);
});
} else {
print("logged out");
}
}
Future<void> signInWithGoogle(BuildContext context) async {
try {
await account.createOAuth2Session(provider: OAuthProvider.google);
// Wait for login to complete and then check session
await Future.delayed(Duration(seconds: 2)); // Let redirect complete
if (await isLoggedIn()) {
// If login was successful, go to BoardWindow
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => BoardWindow(account: account)),
);
}
} catch (e) {
print("OAuth login error: $e");
}
}
ElevatedButton(
onPressed: () {
signInWithGoogle(context);
},
I have also added the activity code for AndroidManifest.xml with project-id in appwrite...
what am i doing wrong?
For anyone facing this issue
Hi everyone! I also ran into this issue today, and I think I managed to solve it.
I updated the flutter_web_auth_2 package to the latest version 5.0.0-alpha.1.
You can do this by adding the following to your pubspec.yaml under dependency_overrides:
dependency_overrides:
flutter_web_auth_2: 5.0.0-alpha.1
I also found this recommendation in the flutter_web_auth_2 package description:
There is also a known problem with task affinities and launch modes (see #113). In order to ensure that flutter_web_auth_2 works correctly, set android:launchMode="singleTop" and remove any android:taskAffinity entries. This configuration is guaranteed to work.
```
Courasy by Egor Tabula
You can solve the flutter_web_auth_2 problem by following this issue. https://discord.com/channels/564160730845151244/1334415894394306571/1334427575790997546
Recommended threads
- Need help to create a wrapper which let ...
I’m looking for help setting up Appwrite properly on a VPS so I can build a self-hosting wrapper around it. The goal is to provide a Linux executable that allow...
- redirect uri not working for OAuth with ...
I'm following this tutorial: https://appwrite.io/blog/post/google-oauth-expo#create-an-expo-app but im using an android development build instead. When I run h...
- Cannot use Apple Oauth2 in React Native/...
Hi! I've trying to add the Apple sign in feature into my Expo App. I followed the docs, but I still receiving the error "Cannot set 'location.href'". Can someon...