Not able to logout from home screen pls review my code and suggest me the changes.
- 1
- Flutter
- Accounts

Sorry, I understand. Those days there were so many people asking things so it's normal to miss your post or have a delay on answers

void logout() async {
try {
final session = await widget.account.get();
print("Current Session: $session");
if (session != null) {
await widget.account.deleteSession(sessionId: session.$id);
print("Session Deleted");
} else {
print("No active session found.");
}
Navigator.of(context).popUntil((route) => route.isFirst);
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) => LoginScreen(
client: widget.client,
account: widget.account,
),
),
);
} catch (e) {
print("Logout error: $e");
// Handle any errors that may occur during logout
if (e is AppwriteException && e.message == "user_session_not_found") {
print("No active session found. Navigating to login page...");
Navigator.of(context).popUntil((route) => route.isFirst);
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) => LoginScreen(
client: widget.client,
account: widget.account,
),
),
);
} else {
}
}
}

Correct

In else you can handle other true errors, like connection issues or server issues

Logout error: AppwriteException: general_unauthorized_scope, User (role: guests) missing scope (account) (401) dont knw whats happening still getting same app started with homescreen and when clicking on logout button showing error

its working but what abt the exception 😅

That means too the user is already logged out

but after logout when i reload the app its still showing the home screen page which should not be showing beacuse i have loged out of the screen right?

From what I understand, the code you sent redirects you when you click logout button?

If so, and if by default you go to home screen, the app will go to home screen

But by default I'm not going to any homescreen

I'm checking it in the main function if the user had logged in move it to the home screen other wise login screen

But after logout and when I reopen the app again it starts with homescreen with no reason

Is that just the default view configued in your Flutter project?

Sorry I fell asleep 😅 did you figure out what account.get is?

No

It will give us the current user info

I thinking of to use provider package to get things sorted out isn't it?

Then the user is still logged in

🤔

btw

you can in fact do:
deleteSession(sessionId: 'current');

to delete the current session

So...account.get
is a function. Calling the function will tell you if the user is logged in or not. The function itself will never be null

account.get != null
will always resolve to true
Recommended threads
- Still an issue? On user deletion, target...
This has been mentioned here: https://discord.com/channels/564160730845151244/1295830646039515146 and as a Github issue here: https://github.com/appwrite/appwri...
- Appwrite database is rounding int values
Hi, i just noticed that appwrite is rounding the value 608542412536545279 to 608542412536545300 in my int array. It seems to somewhat relate to this github iss...
- OAuth fails with Invalid Response or inv...
Im currently trying to use the Discord Oauth but i cant find a way to make it work. I followed the docs and set up the discord oauth application and enabled it...
