Back

401 (Unauthorized)

  • 0
  • Web
  • Databases
  • Auth
  • Storage
  • Cloud
Ankittttt
18 Apr, 2024, 06:26

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

TL;DR
Developers are experiencing a 401 Unauthorized error when trying to log in with Appwrite. The issue seems to stem from missing scopes for users with the role of guests. Despite successful account creation, login attempts fail. However, other functionalities such as creating posts and accessing storage work fine.
Ankittttt
18 Apr, 2024, 06:30

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; } }

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