Getting error "[AppwriteException: User (role: guests) missing scope (account)]" when trying signin
- 0
- Databases
- Auth
- Web
![](https://cdn.discordapp.com/avatars/895312311777099776/6bc2808c64ac1c2533c44fbad4da0d7c.webp)
Hey guys,
I searched the docs, but didn't find a solution. Basically I am making a CRUD app, using react native and email auth in app write. I am getting an error: ERROR [AppwriteException: User (role: guests) missing scope (account)]
And from what I can tell, it is because I am using the account method before intiializing a session in order to check active sessions. So, what's a way to check active sessions on a device without using account.get()? I want to redirect user based on active session type to different screens.
Please help
here is the code snippet that I think is relevant: const handleSignIn = async () => { try { // First check if there is already an active session const sessions = await account.listSessions(); if (sessions.total > 0) { // If session exists, get user details const user = await account.get(); const userProfile = await databases.getDocument('', '', user.$id); navigateBasedOnRole(userProfile); } else { // If no session, create one await account.createEmailPasswordSession(email, password); const user = await account.get(); const userProfile = await databases.getDocument('', '', user.$id); navigateBasedOnRole(userProfile); } } catch (error) { console.error(error); Alert.alert("Error", error.message); } };
![](https://cdn.discordapp.com/avatars/186656408450629633/a_1020a50ae94486c09c02e2868564778d.gif)
You use account.get
const getCurrentUser() {
try {
return account.get();
} catch (err) {
return null;
}
}
...
const user = getCurrentUser();
if(!user) {
redirect('sign-in');
}
![](https://cdn.discordapp.com/avatars/895312311777099776/6bc2808c64ac1c2533c44fbad4da0d7c.webp)
Yes, I tried account.get() earlier but to no avail, it showed the same error
![](https://cdn.discordapp.com/avatars/186656408450629633/a_1020a50ae94486c09c02e2868564778d.gif)
yes, it will show the error if there is no user, that is what it should do
![](https://cdn.discordapp.com/avatars/186656408450629633/a_1020a50ae94486c09c02e2868564778d.gif)
catch the error and handle it
![](https://cdn.discordapp.com/avatars/895312311777099776/6bc2808c64ac1c2533c44fbad4da0d7c.webp)
I can share my gh repo if you want: https://github.com/shafinshaikh/garageappv2
![](https://cdn.discordapp.com/avatars/186656408450629633/a_1020a50ae94486c09c02e2868564778d.gif)
I don't need it
![](https://cdn.discordapp.com/avatars/186656408450629633/a_1020a50ae94486c09c02e2868564778d.gif)
account.get() should throw an error if no one is logged in. You catch that error and handle it appropriately.
Recommended threads
- Cannot get `Realtime` to work, after mov...
I've made a small Android chat application, to tryout the difference features of `Appwrite`. Started by setting up a self hosted solution on a server I have run...
- [react native] creation of a session is ...
I believe my sign-up feature is working -- I can create a user in my app and have it show up on my cloud appwrite users. However, when I try to enter the inform...
- Email OTP not sending email.
Hello. I was able to create and email session token using flutter and I see the user id being created on the cloud Auth but I am not receiving the OTP from appw...
![](/images/bgs/pre-footer.png)