Back

AppwriteException: User (role: guests) missing scope (account)

  • 0
  • Auth
  • Web
0x99
11 Jan, 2024, 06:27

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");

TL;DR
Developers are experiencing an `AppwriteException` error due to a user missing the 'account' scope in a `Svelte` application. This occurs when attempting to fetch user data after a page refresh. A user on the Appwrite Discord channel found a helpful link: https://discord.com/channels/564160730845151244/1089916961896542218. The issue is resolved by managing the user's sign-in state manually, following the guide in the provided link.
Maniac_Fighter
11 Jan, 2024, 06:28

are you sure you are loggedIn?

Maniac_Fighter
11 Jan, 2024, 06:28

account.get() usually returns the current loggedIn user

0x99
11 Jan, 2024, 06:29

yes i am changing route and calling function in root layout

Maniac_Fighter
11 Jan, 2024, 06:31

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?

sinans
21 Jan, 2024, 20:13

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:

TypeScript
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
ELIFECYCLECommand failed with exit code 1.

src/routes/(app)/users/[userId]/+page.svelte:

TypeScript
<script lang="ts">
    ...
    import { getAccount } from '$lib/appwrite/account';
    getAccount().then((account) => {
        console.log(account);
    });
</script>
<div>...</div>
sinans
21 Jan, 2024, 20:20

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

tsusui rei
15 Feb, 2024, 12:56

Is there any solution about this one

tsusui rei
15 Feb, 2024, 12:56

I also get same error when fetching user after logged in

D5
15 Feb, 2024, 13:34

Please, create a separate post with this 😄

SHADOW07
15 Feb, 2024, 14:19

const isUser1 = await account.get();

SHADOW07
15 Feb, 2024, 14:19

this code return a promise

SHADOW07
15 Feb, 2024, 14:19

if you loged in , then it's should return your info

SHADOW07
15 Feb, 2024, 14:19

const isUser1 = await account.get().then((res)=>console.log(res))

tsusui rei
16 Feb, 2024, 08:41

I still get an error, is it because of permission when register?

SumitBando
7 Mar, 2024, 16:46

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

ideclon
7 Mar, 2024, 19:01

No, this will return an Account object, not a Promise (because OP used await

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more