I'm trying to register a new user and then sign them in but got this error: - Error: AppwriteException: User (role: guests) missing scope (account)
Here's the code
// Register user
export async function createUser(email, password, username) { try { const newAccount = await account.create( ID.unique(), email, password, username );
if (!newAccount) throw Error;
const avatarUrl = avatars.getInitials(username);
await signIn(email, password);
const newUser = await databases.createDocument(
appwriteConfig.databaseId,
appwriteConfig.userCollectionId,
ID.unique(),
{
accountId: newAccount.$id,
email: email,
username: username,
avatar: avatarUrl,
}
);
return newUser;
} catch (error) { throw new Error(error); } }
// Sign In
export async function signIn(email, password) { try { await account.deleteSessions(); await account.deleteSession("current"); const session = await account.createEmailPasswordSession(email, password);
return session;
} catch (error) { throw new Error(error); } }
// Get Account export async function getAccount() { try { const currentAccount = await account.get();
return currentAccount;
} catch (error) { throw new Error(error); } }
// Get Current User
export async function getCurrentUser() { try { const currentAccount = await getAccount(); if (!currentAccount) throw Error;
const currentUser = await databases.listDocuments(
appwriteConfig.databaseId,
appwriteConfig.userCollectionId,
[Query.equal("accountId", currentAccount.$id)]
);
if (!currentUser) throw Error;
return currentUser.documents[0];
} catch (error) { console.log(error); return null; } }
Any insights or suggestions on how to fix this would be greatly appreciated! Thanks in advance!
please use code formatting to make it more readable.
use back ticks
AppwriteException: User (role: guests) missing scope (account)
this error means that current session user is not authenticated
in sign in function you dont have to delete sessions on server side. you can directly create new session.
can u specify where the error is coming from??
Recommended threads
- DB Relational Table Request
Hi, I'd like to suggest a rewording of the relationships between tables. - Current wording: storeOperatingDays can contain one storeId ...
- Domain is already used. Please try again...
I have a website with where the www.domain.me This website works just fine But if I try to visit domain.me. I get this error. I keep getting sent to some app ri...
- Redirect from clicking team invite link ...
Hi all! Pretty new to app development in general so this might be something more generic than appwrite, but I've found (after reading the docs for the Teams API...