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
- Invalid origin error in authentication
I have setup the package name same as the package name in app.json but it is constantly saying `AppwriteException: Invalid Origin. Register your new client as ...
- TLS provisioning failure for custom doma...
Hi Appwrite team, we’re using Appwrite Sites and TLS provisioning for our custom domain fails. Domain: somnara.app Error: Failed to create TLS subscription –...
- Functions Problem
Whenever I run my AI Generate through Appwrite Functions, I am getting this Call Stack AIService.generateServer (src\services\ai\gemini.ts) next (<native>) ...