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
- [SOLVED] curl error Number: 6 — function...
Hello, I invested a lot of time in this error in a fresh install of appwrite 1.8.1 and lasted until fix, this if for helping anyone that can have the same weird...
- android platform invaild origina
It happened today suddenly. Our app says invalid origin. And appwrite cloud says every time we tried to add the app to it: "param platformId" is not optional.
- Team invite - 500 error - no email
When executing ```dart await _repository.teams.createMembership( teamId: event.listId, roles: ['member'], email: event.email, url: 'xxxx', ); ``` I se...