I am using Appwrite to build a client side website (an e-commerce online store). There is a database made in appwrite which has the admin users as well as the customers collections. Now whenever I load the page without being logged in I get the following error: AppwriteException: User (role: guests) missing scope (account)
In the products and categories collection, I have ensured that Any
have the role to read the documents only. Whereas I have added an admin teams in the Auth tab (where all the admins are the members).
I want to make sure that guests to the client website, are able to only read the documents. Btw I am using reactjs and appwrite Below is the appwrite backend code, I have written:
const getCurrentUser = async () => {
try {
const currentUser = await account.get();
if (currentUser) {
return currentUser;
}
} catch (e) {
console.error(e);
}
};
const registerUser = async (userData) => {
try {
const user = await account.create(
ID.unique(),
userData.email,
userData.password,
userData.name
);
if (user) {
await loginUser({ email: userData.email, password: userData.password });
} else {
return undefined;
}
} catch (error) {
console.error(error);
}
};
const loginUser = async (loginDetails) => {
try {
return await account.createEmailSession(
loginDetails.email,
loginDetails.password
);
} catch (error) {
console.error(error);
}
};
const deleteCurrentSession = async () => {
try {
const {$id} = await getCurrentUser();
// return await account.deleteSession("current");
return await account.deleteSession($id);
} catch (error) {
console.error(error);
}
};
The getCurrentUser() runs everytime the app is refreshed, so in the console I am getting the above given error Note: Also I am not able to logout, the session isn't getting deleted.