
I am getting this error after logging in through createEmailSession(email, password);
I have a logout button that i use to deleteSession(sessionId: 'current') but apparently the current session seems to be null or not properly created as per the above error.
Any ideas ?
I checked the error and it seems that we need to be logged in but thats what i thought we are doing when we created an email session.

You get the "User (role: guests) missing scope (account)"
error when you you run createEmailSession
or when you're trying to logout?

when i am trying to logout

Okay, So what I will suggest is that you'll check if the user is even logged in

Future<UserModel?> login(String email, String password) async {
logger.d("Inside login");
try {
aw_models.Session session =
await account.createEmailSession(email: email, password: password);
aw_models.Document? userDoc = await fetchUserByEmail(email);
if (userDoc != null) {
UserModel? user = UserModel.fromJson(userDoc.data);
return user;
}
} catch (e) {
logger.e('Login failed.');
rethrow;
}
return null;
}
Future<void> logout() async {
try {
var curr = await account.getSession(sessionId: 'current');
var response = await account.deleteSession(sessionId: curr.$id);
} on AppwriteException catch (e) {
logger.e("Failed to delete session", e.toString());
throw Fail(
code: e.code ?? 500,
message: "Failed to logout the current user",
response: e.response);
}
}
Code snippets for reference

For example
if(await checkIfUserLoggedIn){
await account.deleteSession('current')
}
async checkIfUserLoggedIn(){
try{
await account.get();
return true;
} catch (e){
print(e);
return false;
}
}

apparently i did that with this
var curr = await account.getSession(sessionId: 'current');

When you're running two await in single catch
var curr = await account.getSession(sessionId: 'current');
var response = await account.deleteSession(sessionId: curr.$id);
It will be hard to know which one cause the catch

This will also work

both lines give the same error. sorry for confusion, i actually added that just now for debugging
Recommended threads
- Redirect URL sends HTTP instead of HTTPS...
I am not sure since when this issue is present, but my Google and Apple redirect URI are no longer pointing to the HTTPS redirect URI when I try to use OAuth. ...
- Failing to run document operations on sd...
Could someone point me in the right direction I'm going in cirlces. I have a problem with sdks and my self-hosted server in production (for ~3 years) I have bee...
- Functions fail to deploy after switching...
Hi <@1087889306208718959> , after switching my self-hosted Appwrite instance to use AWS S3 as the storage backend, my Cloud Functions stopped working. I’m runni...
