I am getting the Following error while running my typeScript code I am also using appwrite for my application

75 views Asked by At
Failed to load resource: the server responded with a status of 401 ()
api.ts:88 AppwriteException: User (role: guests) missing scope (account)
    at Client.<anonymous> (http://localhost:5173/node_modules/.vite/deps/appwrite.js?v=fed2c2f0:850:17)
    at Generator.next (<anonymous>)
    at fulfilled (http://localhost:5173/node_modules/.vite/deps/appwrite.js?v=fed2c2f0:488:24)

I did try checking the endpoints of API key, but it didn't work. What can I try next?

1

There are 1 answers

0
Samarthanand Kamble On

Not sure where exactly its causing error to you but I have also encountered this issue.

Context for why I've encountered - The user is already authenticated, but when reloads/refresh the page, it redirected them to the signin page (as I've logic to redirect but only if user is not authenticated).

To avoid this I've invoked a function in useEffect which presists the user instead of redirecting.(If authenticated)

Now on signup/sigin page when the user is not authenticated it logs me that error and it's known.

Please check once when you're trying to fetch account details is the user authenticated ? As in my case user is not authenticated and I'm trying to fetch the details which leads cause that issue.

Here is my code snippet for reference :

 useEffect(() => {
    getUserOnLoad();
  }, []);

  const getUserOnLoad = async () => {
    try {
      const accountDetails = await account.get();
      setUser(accountDetails);
    } catch (error) {
      console.warn(error?.message);
    } finally{
      setLoading(false);
    }
  };