Back

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

  • 6
  • Users
  • Accounts
  • Web
Ayush
7 Dec, 2023, 10:06

Yes, But it worked for me for the first time I implemented it

TL;DR
The user is encountering an AppwriteException with the message "User (role: guests) missing scope (account) 401." They are trying to fetch user information using Appwrite's getUserInfo() function but are getting an error. The user provides their code for reference which includes a register.js file and an auth.js file. Possible solution: The user is advised to try using account.get() instead of getUserInfo() to see if it works. The user is also encouraged to check the response headers of the /redirect request to see what the set cookie is, as it may be causing the error. Additionally, creating a new project could
D5
7 Dec, 2023, 10:14

Then probably creating a new project should solve it

D5
7 Dec, 2023, 10:15

Except if it's an issue with your code

Ayush
7 Dec, 2023, 10:23

Let me try this also

Ayush
7 Dec, 2023, 10:32

Did, not working

Ayush
7 Dec, 2023, 10:34
TypeScript
import { Account, Client } from "appwrite";
import appwriteConf from "../config/appwriteConfig";

export class AuthService {
  client = new Client();
  account;

  constructor() {
    this.client
      .setEndpoint(appwriteConf.appwriteAPI)
      .setProject(appwriteConf.appwriteProjectId);

    this.account = new Account(this.client);
  }

  async signInWithGoogle() {
    try {
      return this.account.createOAuth2Session(
        "google",
        "http://localhost:5173/register",
        "http://localhost:5173/"
      );
    } catch (error) {
      console.log(`Error while logging In: ${error}`);
    }
  }

  async getUserInfo() {
    try {
      const session = await this.account.getSession('current');
      console.log(session);
      return session;
    } catch (error) {
      console.log(`Error while Fetching user: ${error}`);
    }
  }
}

const authService = new AuthService();

export default authService;
Ayush
7 Dec, 2023, 10:34

auth.js

Ayush
7 Dec, 2023, 10:35

register.js

TypeScript
    try {
      await authService.getUserInfo();
    } catch (error) {
      console.log(`Error while Fetching user: ${error}`);
    }
  };

  useEffect(() => {
    getUser();
  }, []);
Ayush
7 Dec, 2023, 10:35

This is my code

D5
7 Dec, 2023, 10:43

Do you get error logging in?

D5
7 Dec, 2023, 10:43

Are you using any framework?

Ayush
7 Dec, 2023, 10:47

Vite + React

Ayush
7 Dec, 2023, 10:47
D5
7 Dec, 2023, 10:48

I see. As long as you don't use any SSR feature it will be fine

Ayush
7 Dec, 2023, 10:48

Okay

D5
7 Dec, 2023, 10:48

You're trying to get current user info, true?

D5
7 Dec, 2023, 10:50

Try using account.get(); instead. Let's see if it works

Ayush
7 Dec, 2023, 11:01

wait

Ayush
7 Dec, 2023, 11:03

same error

Drake
7 Dec, 2023, 12:04

Would you please sign in using oauth, but have the network logs open to capture all of the network requests? I think the request that sets the cookie is the /redirect request. Look in the response headers of that request to see what the set cookie is

Ayush
7 Dec, 2023, 16:40

It's just these two requests

Ayush
7 Dec, 2023, 16:41
Drake
7 Dec, 2023, 16:59

there should be some more. it wont be a fetch request. probably a doc request

Ayush
7 Dec, 2023, 17:05

where can I see them?

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