#AppwriteException: User (role: guests) missing scope (account)
21 messages · Page 1 of 1 (latest)
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/[email protected]/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/[email protected]/node_modules/appwrite/dist/esm/sdk.js:391:27)
at Generator.next (<anonymous>)
at fulfilled (file://{project-path}/node_modules/.pnpm/[email protected]/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)
I don’t see any issues with the code there?
You right , it confuses me sometimes when console log it
hi anyone get solution for this error 😅😅
If you're facing it, create a new post with your code so we help you as this is an old thread and things could have changed since then