AppwriteException: general_unauthorized_scope, User (role: guests) missing scope (account) (401)
- 0
- Flutter

Before loggin out you can check if the user is even logged in by running the account.get()
inside try catch

yes I am loggedin before I logout

In between you're also required to get the session by using account.get()
Can you test when you're using the account.get()
right after login?

I just tried to login and it took 5 tries to login

after 5 tries it worked but other 4 gave the error

logout([bool deleteSessions = true]) async {
state = const AuthState(isLoggedIn: false);
if (deleteSessions) {
Client client = ref.read(appwriteClientProvider);
Account account = Account(client);
try {
var acc = await account.get();
await account.deleteSessions();
} catch (e) {
log(e.toString());
}
}
}

What was the error when you tried to log in?

AppwriteException: general_unauthorized_scope, User (role: guests) missing scope (account) (401)

When login?

yes I get this error when I try to login not try to logout

await account.createOAuth2Session(provider: 'apple');
login() async {
try {
Client client = ref.read(appwriteClientProvider);
Account account = Account(client);
var appwriteUser = await account.get();
} catch (e) {
log("auth_provider Login error: $e");
Sentry.captureException(e);
}
}```

Where is the login it self?

You still need to create the session

Like createEmailSession

I use oauth2

Can you share the code flow

okay

AppleAuthButton(
onPressed: () async {
await account.createOAuth2Session(provider: 'apple');
return _completeLogin();
},
themeMode: ThemeMode.light,
),
void _completeLogin() async {
await ref.read(authProvider.notifier).login();
}
login() async {
try {
Client client = ref.read(appwriteClientProvider);
Account account = Account(client);
var appwriteUser = await account.get();
state = AuthState(
isLoggedIn: true,
userId: appwriteUser.$id,
fullName: appwriteUser.name,
email: appwriteUser.email,
kollektorId: kUser["id"]);
} catch (e) {
log("auth_provider Login error: $e");
Sentry.captureException(e);
}
}

Can you add try catch here
AppleAuthButton(
onPressed: () async {
try {
await account.createOAuth2Session(provider: 'apple');
return _completeLogin();
} catch (e) {
// log here
}
},
themeMode: ThemeMode.light,
),

i did

it doesnt catch anything there even there is a general_unauthorized_scope error

createOAuth2Session
doesn't return the session, you need to add your logic in the success URL

i believe it doesnt explain the inconsistency with the login

it only happens time to time

Just think this: when you start createOAuth2Session
you go to a new page, this is a third party page, appwrite can't follow the state, that is why you need to continue your flow with the success
and failed
URL. It maybe works time to time because a previous session I'm not sure, but if you change your flow, it will always work
Recommended threads
- 503 Timeout when Updating or Upserting D...
Hey I’m running into an issue when trying to update or upsert a row in Appwrite. The request hangs for a while and then throws this error: ``` AppwriteException...
- Hola equipo de soporte,
Hola equipo de soporte, Estoy desarrollando una Function en Appwrite Cloud con Node.js 22 y el siguiente package.json: { "name": "upload-whitelist", "type"...
- Sites 30MB limit from GitHub
I’m deploying a site from github as Other type on the Hobby plan. It is actually a Flutter web app but it’s in a subdirectory with the root being an html landin...
