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
- Current User is Not authorized
recreating same Thread
- Apple OAuth Scopes
Hi Hi, I've configured sign in with apple and this is the response i'm getting from apple once i've signed in. I cant find anywhere I set scopes. I remember se...
- Sign In With Apple OAuth Help
Hi All! I've got a flutter & appwrite app which Im trying to use sign in with apple for. I already have sign in with google working and the function is the sam...