Hello everyone, I'm facing an issue in my project, called 401 Unauthorized AppwriteException: User (role: guests) missing scope (account, I'm appwite for backend as a servvice. when I'm creating an new account it will succussfully creates buut when I'm trying to LOGIN it dos'nt login . But if i try to go manually on Home page the i can go even i can create a post its working, and storage is also working but not with loggin
import { ID, Query } from "appwrite"; import { appwriteConfig, account, databases, storage, avatars } from "./config"; import { IUpdatePost, INewPost, INewUser, IUpdateUser } from "@/types"; export async function createUserAccount(user: INewUser) { try { const newAccount = await account.create( ID.unique(), user.email, user.password, user.name ); if (!newAccount) throw Error; const avatarUrl = avatars.getInitials(user.name); const newUser = await saveUserToDB({ accountId: newAccount.$id, name: newAccount.name, email: newAccount.email, username: user.username, imageUrl: avatarUrl, }); return newUser; } catch (error) { console.log(error); return error; } } export async function signInAccount(user: { email: string; password: string }) { try { const session = await account.createEmailSession(user.email, user.password); return session; } catch (error) { console.log(error); } } export async function saveUserToDB(user: { accountId: string; name: string; email: string; imageUrl: URL; username?: string; }) { try { const newUser = await databases.createDocument( appwriteConfig.databaseId, appwriteConfig.userCollectionId, ID.unique(), user ); return newUser; } catch (error) { log(error) } } export async function getAccount() { try { const currentAccount = await account.get(); return currentAccount; } catch (error) { console.log(error); } } 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; } }
Recommended threads
- Need help with createExecution function
Hi, Need some help understanding createExecution. When requesting function execution via createExecution, the function handler arguments are incorrect and rese...
- Query Appwrite
Hello, I have a question regarding Queries in Appwrite. If I have a string "YYYY-MM", how can I query the $createdAt column to match this filter?
- Need Help with Google OAuth2 in Expo usi...
I'm learning React Native with Expo and trying to set up Google OAuth2 with Appwrite. I couldn't find any good docs or tutorials for this and my own attempt did...