[SOLVED] User (role: guests) missing scope (account) when checking for an active session
- 0
- Android

Hi everyone
I'm working on an android app and i need to check if the user is logged in and has an active session. According to the manual @ https://appwrite.io/docs/authentication, this can be done using account.get().
Problem is, it throws an AppwriteException: User (role: guests) missing scope (account).
Is this to be expected? If this is the case, i would add a try catch in the docs example (or add the returned exception) 🙂
Thanks

Yes this is the right behavior, You can check if the error code is 401 that mean user_unauthorized
You can see all error codes here https://appwrite.io/docs/response-codes

Ok, thank you 😃

[SOLVED] User (role: guests) missing scope (account) when checking for an active session

so is there way to avoid this error ? I am getting the same error while doin the same - checking if user session is active when the component mount


It's seems like the user isn't logged in. And if it is the case then the 401 is okay

would It be better if I catch the error and do nothing with it instead

This is one way of handling it sure It really depends on your flow.
If for example you're checking if the user is connect each time the window is loaded then you can leave the catch block empty

👍

val account = Account(client) var loggedIn = false try { val session = account.get() loggedIn = true } catch (e: AppwriteException) { ... }
if (!loggedIn) { try { val session = account.createEmailSession( email = "abc", password = "xyz" ) } catch (e: AppwriteException) { ... } } Something like this
Recommended threads
- Adding "name" column to table creates 2-...
As stated, im adding the "name" column to one table, it adds 4 duplicates. In another table it adds 3 duplicates, and when I delete 1 of them, all duplucates di...
- Google signin with appwrite
I want to use Google sign in in android and create session from idToken using appwrite. But, i don't know if it's achievable or not. because i don't want to use...
- Realtime didn't work in react native exp...
``` useEffect(() => { const { client } = createClient(); const unsubscribe = client.subscribe(`databases.${process.env.EXPO_PUBLIC_APPWRITE_DATABASE}.t...
