How to resolve this error I am currently login with an account but trying to get my own account info this is showing this error. Error : AppwriteException: User (role: guests) missing scope (account) Code : const isUser1 = await account.get(); const isUser2 = await account.getSession("current");
are you sure you are loggedIn?
account.get() usually returns the current loggedIn user
yes i am changing route and calling function in root layout
route changing doesn't necessarily means you are loggedIn. It could be unprotected routes.
When calling another services (databases, storage ), do you still get the above error?
Context:
I have a Svelte
application where users log in using their Google account. After logging in, users are redirected to the home page, and then they can navigate to their user page. The user page is located at src/routes/(app)/users/[userId]/+page.svelte
.
Issue:
On the user page, I am using getAccount() function from $lib/appwrite/account
to fetch and display the user's account data. The account data logs to the console successfully if the page is not refreshed. However, when I refresh the page, I encounter an AppwriteException
error stating that the user (with the role of 'guests') is missing the 'account' scope
.
Error:
file:///{project-path}/node_modules/.pnpm/appwrite@13.0.1/node_modules/appwrite/dist/esm/sdk.js:391
throw new AppwriteException(data === null || data === void 0 ? void 0 : data.message, response.status, data === null || data === void 0 ? void 0 : data.type, data);
^
AppwriteException: User (role: guests) missing scope (account)
at Client.<anonymous> (file:///{project-path}/node_modules/.pnpm/appwrite@13.0.1/node_modules/appwrite/dist/esm/sdk.js:391:27)
at Generator.next (<anonymous>)
at fulfilled (file://{project-path}/node_modules/.pnpm/appwrite@13.0.1/node_modules/appwrite/dist/esm/sdk.js:22:58)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 401,
type: 'general_unauthorized_scope',
response: {
message: 'User (role: guests) missing scope (account)',
code: 401,
type: 'general_unauthorized_scope',
version: '0.12.45'
}
}
Node.js v20.10.0
ELIFECYCLE Command failed with exit code 1.
src/routes/(app)/users/[userId]/+page.svelte:
<script lang="ts">
...
import { getAccount } from '$lib/appwrite/account';
getAccount().then((account) => {
console.log(account);
});
</script>
<div>...</div>
I found out that the way it's working is normal. At first, I thought Appwrite SDK would take care of the user's sign-in state by itself. But now I see we have to do it on our own, especially when the page gets refreshed in a Svelte app.
If you have the same problem, I found a helpful link. Here it is for anyone who needs it: https://discord.com/channels/564160730845151244/1089916961896542218
Is there any solution about this one
I also get same error when fetching user after logged in
Please, create a separate post with this 😄
const isUser1 = await account.get();
this code return a promise
if you loged in , then it's should return your info
const isUser1 = await account.get().then((res)=>console.log(res))
I still get an error, is it because of permission when register?
The SvelteKit tutorial at https://appwrite.io/docs/tutorials/sveltekit/step-4 seems to be of poor quality, the landing page tries to createUser() before login, and has the same error. Many other issues
No, this will return an Account object, not a Promise (because OP used await
Recommended threads
- Query Appwrite
Hello, I have a question regarding Queries in Appwrite. If I have a string "YYYY-MM", how can I query the $createdAt column to match this filter?
- Different appwrite IDs are getting expos...
File_URL_FORMAT= https://cloud.appwrite.io/v1/storage/buckets/[BUCKET_ID]/files/[FILE_ID]/preview?project=[PROJECT_ID] I'm trying to access files in my web app...
- Invalid document structure: missing requ...
I just pick up my code that's working a week ago, and now I got this error: ``` code: 400, type: 'document_invalid_structure', response: { message: 'Inv...