
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
- "Memberships privacy" setting in 1.7.4
Hi everyone, I'm experiencing an issue with a clean self-hosted installation of Appwrite version 1.7.4. I previously used version 1.6.1, and if I remember corre...
- Function 404 error - Deployment with the...
I have a function in my Appwrite Cloud (free plan) project that cannot be accessed or deleted (404 in both UI and CLI). I'm stuck at the 5 functions limit and c...
- 1.6 to 1.7 does not work
Appwrite (self-hosted) stopped working after updating from 1.6.2 that was stable. Getting the general_server_error. Mentioning I fallowed all steps for upgrad...
