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
- Error with realtime channels
I'm performing a subscription to realtime channels, and after a few seconds I get an exception with this error: {\"type\":\"error\",\"data\":{\"code\":1008,\"me...
- Which flutter SDK version for Self Hoste...
Hi all, Is there a good way to figure out which version of flutter SDK and Dart SDK is current for latest available self-hosted 1.8.0 ? I know new features are...
- redirect_uri errors on flutter client
Hi all, I'm using the flutter client for my app to do appwrite auth and use the JWTs to send to my backend. When I try to sign in with SSO, I get this: https:/...