Back
[AppwriteException: User (role: guests) missing scope (account)]
- 0
- Databases
- React Native
- Apple
- Auth
I'm trying to make an app using expo and react-native. When I try to get the current user I get the error "[AppwriteException: User (role: guests) missing scope (account)]". I have narrowed it down to being in my getCurrentUser function when I do account.get(). Here is that function :
TypeScript
export const getCurrentUser = async () => {
try {
console.log("1")
const currentAccount = await account.get();
console.log("2")
if(!currentAccount) throw Error("No current account");
console.log(currentAccount)
const currentUser = await databases.listDocuments(
config.databaseId,
config.userCollectionId,
[Query.equal('accountId', currentAccount.$id)]
)
console.log(currentUser)
if(!currentUser) throw Error("No user found for current account");
return currentUser.documents[0];
} catch (error) {
console.log("error")
console.log(error)
}
}
And here are the logs I get when it runs so you can see that it errors on the account.get:
TypeScript
LOG 1
LOG error
LOG [AppwriteException: User (role: guests) missing scope (account)]
LOG NOT logged in current user
Here is where I call that funciton in my global context file:
TypeScript
useEffect(() => {
getCurrentUser()
.then((res) => {
if(res) {
console.log("logged in current user")
setIsLoggedIn(true);
setUser(res);
} else {
console.log("NOT logged in current user")
setIsLoggedIn(false);
setUser(null);
}
})
.catch((error) => {
console.log(error);
})
.finally(() => {
setisLoading(false);
}
);
}, []);
Sorry im new to react-native and appwrite so any help would be appreciated
TL;DR
Developers encountered an error "[AppwriteException: User (role: guests) missing scope (account)]" while trying to get the current user in a React Native app using Expo. The issue arises in the `getCurrentUser` function during the `account.get()` call. The error is thrown due to the user having the role 'guests' but lacking the necessary scope for the account. Ensure the user's role has the required scope to access the account.Recommended threads