Back

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

  • 0
  • Auth
Aarush Acharya
6 Jul, 2024, 13:37
TypeScript

  Future<void> loginWithGoogle() async {
    try {
    await account.createOAuth2Session(provider: OAuthProvider.google);
    await isUserLoggedIn();
    } catch (error) {
      log(error.toString());
    }

  }

  Future<void> isUserLoggedIn() async {
    try {
      await setUserProfileData();
      if (isUserProfileComplete == false) {
        Get.offNamed(AppRoutes.onBoarding);
      } else {
        Get.offNamed(AppRoutes.tabview);
      }
    } catch (e) {
      bool? landingScreenShown = GetStorage().read(
          "landingScreenShown"); // landingScreenShown is the boolean value that is used to check wether to show the user the onboarding screen or not on the first launch of the app.
      landingScreenShown == null
          ? Get.offNamed(AppRoutes.landing)
          : Get.offNamed(AppRoutes.login);
    }
  }

  Future<void> setUserProfileData() async {
    isInitializing.value = true;
    try {
      print("here before getting account");
      appwriteUser = await account.get();
      print("ran get account success fully");
      displayName = appwriteUser.name;
      email = appwriteUser.email;
      isEmailVerified = appwriteUser.emailVerification;
      uid = appwriteUser.$id;
      isUserProfileComplete =
          appwriteUser.prefs.data["isUserProfileComplete"] ?? false;
      if (isUserProfileComplete == true) {
        Document userDataDoc = await databases.getDocument(
            databaseId: userDatabaseID,
            collectionId: usersCollectionID,
            documentId: appwriteUser.$id);
        profileImageUrl = userDataDoc.data["profileImageUrl"];
        profileImageID = userDataDoc.data["profileImageID"];
        userName = userDataDoc.data["username"] ?? "unavailable";
      }
      update();
    } catch (e) {
      log(e.toString());
    } finally {
      isInitializing.value = false;
    }
  }
TL;DR
Developers are encountering a '401 missing scope (account)' error after a user logs in with Google on their app. The issue seems to be related to the user's session and account details. The code provided includes functions for Google login and user profile data retrieval. To resolve the error, ensure that the necessary account scope is properly set up and that user profile data is being retrieved correctly.
Aarush Acharya
6 Jul, 2024, 13:38

I check my appwrite console after google login a user is created in the auth section and a session is also there i am not able to understand why is this error there

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