Back

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

  • 0
  • Android
maned3v
27 Mar, 2023, 14:20

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

TL;DR
User is trying to check if a user is logged in and has an active session, but is getting an error message "User (role: guests) missing scope (account)" when using the account.get() method. The error can be ignored and the catch block can be left empty. The error code 401 indicates that the user is unauthorized. The user can refer to the documentation for a list of error codes.
Binyamin
27 Mar, 2023, 14:29

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

maned3v
27 Mar, 2023, 14:33

Ok, thank you 😃

maned3v
27 Mar, 2023, 14:33

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

Hmm
2 Apr, 2023, 03:57

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

Hmm
2 Apr, 2023, 03:58
Binyamin
2 Apr, 2023, 03:59

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

Hmm
2 Apr, 2023, 03:59

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

Binyamin
2 Apr, 2023, 04:01

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

Hmm
2 Apr, 2023, 04:06

👍

maned3v
18 Apr, 2023, 10:17

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

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more