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

21 messages · Page 1 of 1 (latest)

junior wagon
#

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

sharp crypt
#

are you sure you are loggedIn?

#

account.get() usually returns the current loggedIn user

junior wagon
#

yes i am changing route and calling function in root layout

sharp crypt
#

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?

peak citrus
#

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

eternal pawn
#

Is there any solution about this one

#

I also get same error when fetching user after logged in

modern crane
mortal kelp
#

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

eternal pawn
#

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

coral lynx
gleaming agate
gleaming agate
mortal kelp
vague shadow
#

hi anyone get solution for this error 😅😅

modern crane