Back

AppwriteException: User (role: guests) missing scope (account)

  • 0
  • Databases
  • Auth
  • Web
Thoufiq Uchiha🥷👨💻
18 Apr, 2024, 16:02

Hello please help me solve this This is auth.js

TypeScript
import conf from "../conf/conf.js"
import { Client, Account, ID } from "appwrite";

export class AuthService {
    client = new Client();
    account;

    constructor(){
        this.client
        .setEndpoint(conf.appwriteUrl)
        .setProject(conf.appwriteProjectId)
        this.account = new Account(this.client)
    }

    async createAccount({email, password, name}){
        try {
            const userAccount = await this.account.create(ID.unique(), email, password, name)
            if (userAccount) {
                return login({email, password})
            } else {
                return userAccount
            }
        } catch (error) {
            throw error
        }
    }
    async login({email, password}){
        try {
            return await this.account.createEmailSession(email, password)
        } catch (error) {
            throw error
        }
    }
    async getCurrentUser(){
        try {
            return await this.account.get()
        } catch (error) {
            console.log("Appwrite service :: getCurrentUser() :: ", error)
        }
        return null
    }
    async logout(){
        try {
            await this.account.deleteSessions()
        } catch (error) {
            console.log("Appwrite service :: logout() :: ", error)
        }
    }
}

const authService = new AuthService()

export default authService
TL;DR
AppwriteException: User (role: guests) missing scope (account); Developer is seeking help with solving an issue in their auth.js file. The AuthService class is missing the necessary scope for a guest user. The createAccount function seems to be calling a login function that is not defined. Solution: Add the missing scope for the guest role in the auth.js file. Ensure the login function is properly defined and called within the createAccount function.
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