Flutter Developer
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?