Skip to content
Back

[Error: User (role: guests) missing scope (account)]

  • 0
  • Android
  • Auth
  • React Native
zulu
7 Jun, 2024, 06:51

I am trying to create an account on the project am working on and it creates cause I could see the account on the Auth, but instead of it to push me to the home page after signing in or sign up, it shows this error [Error: User (role: guests) missing scope (account)]

TL;DR
Developers are encountering an error "[Error: User (role: guests) missing scope (account)]" when trying to sign in or sign up users. The issue likely stems from a missing scope in the appwrite.js file. Check the scope settings in the account creation process and ensure proper permissions for users. Potential solution: Update the account creation process in the appwrite.js file to include the necessary scope for users to sign in successfully.
zulu
7 Jun, 2024, 06:53

This is the appwrite.js file

import { Client, Account, ID, Avatars, Databases } from "react-native-appwrite"; export const config = { endpoint: "https://cloud.appwrite.io/v1", platform: "com.zido.flexfury", projectId: "6662901b0020e12fba5d", databaseId: "666293ff001d5704f3f7", userCollectionId: "6662954c000d71580730", storageId: "6662965c0037c6a4e833", }; const client = new Client();

client .setEndpoint(config.endpoint) // Your Appwrite Endpoint .setProject(config.projectId) // Your project ID .setPlatform(config.platform); // Your application ID or bundle ID

const account = new Account(client); const avatars = new Avatars(client); const databases = new Databases(client);

export const createUser = async (email, password, username) => { try { const newAccount = await account.create( ID.unique(), email, password, username );

TypeScript
if (!newAccount) throw new Error("Account creation failed");
const avatarUrl = avatars.getInitials(username);
const session = await signIn(email, password);

if (!session) throw new Error("Sign in failed");

// Create a new document in the database for the user
const newUser = await databases.createDocument(
  config.databaseId,
  config.userCollectionId,
  ID.unique(),
  {
    accountId: newAccount.$id,
    email: email,
    username: username,
    avatar: avatarUrl,
  }
);

return newUser;

} catch (error) { console.error(error); throw new Error(error.message); } };

// Sign In export async function signIn(email, password) { try { // Delete any existing session for the user await account.deleteSession("current");

TypeScript
// Create a new session with email and password
const session = await account.createEmailSession(email, password);

return session;

} catch (error) { console.error(error); throw new Error(error.message); } }

zulu
7 Jun, 2024, 06:55

This is what my code to submit looks like for both sign in and sign up

const [form, setForm] = useState({ username: "", email: "", password: "", });

const submit = async () => { if (!form.username === "" || !form.email === "" || !form.password === "") { Alert.alert("Error", "Please fill in all fields"); }

TypeScript
setIsSubmitting(true);
try {
  const result = await createUser(form.email, form.password, form.username);

  router.replace("/home");
} catch (error) {
  Alert.alert("Error", error.message);
} finally {
  setIsSubmitting(false);
}

};

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