Back

How to chnage user permissions

  • 0
  • Users
  • Web
sanujitmajhi 🐻 ⛓
16 Feb, 2024, 14:53

AppwriteException: User (role: guests) missing scope (account) at Client.<anonymous> (http://localhost:5173/node_modules/.vite/deps/appwrite.js?v=5dc19954:850:17) at Generator.next (<anonymous>) at fulfilled (http://localhost:5173/node_modules/.vite/deps/appwrite.js?v=5dc19954:488:24)

TL;DR
The developer is trying to change user permissions but is encountering an error where the user is not logged in. They are using the Appwrite library for authentication. The specific error message they are receiving is `AppwriteException: User (role: guests) missing scope (account)`. The error occurs when calling the `getcurrentuser()` function of the `Authservice` class. Solution: The error is expected because the user is not logged in. To fix the error, the developer should handle this error case appropriately in their code. They can check if the returned user data is null and logout the user if necessary.
Binyamin
16 Feb, 2024, 14:53

Can you share the code?

sanujitmajhi 🐻 ⛓
16 Feb, 2024, 14:54

yaa sure is there anu commnd to store in thread or directly i will send here

sanujitmajhi 🐻 ⛓
16 Feb, 2024, 14:55

import authservice from './Services/Auth';

import './index.css' /* eslint-disable no-undef */ import React, { useEffect, useState } from 'react'; import './App.css'; import { useDispatch } from 'react-redux'; import { Header, Footer } from './components'; import { login, logout } from './store/authslice';

function App() { const [isLoading, setIsLoading] = useState(true); const dispatch = useDispatch();

useEffect(()=>{

TypeScript
 authservice.getcurrentuser()
 .then((userData)=>{
  if (userData){
    dispatch(login({userData}))


  }
  else{
       dispatch(logout())
  }


 })
 .finally(()=>setIsLoading(false))

},[])

return !isLoading ?( <div className='min-h-screen flex flex-wrap content-between bg-gray-400'>

TypeScript
    <div className='w-full block'>

       <Header/>



       <Footer />

    </div>


</div>

):null

}

export default App;

Binyamin
16 Feb, 2024, 14:56

So the error is from

TypeScript
 authservice.getcurrentuser()

This is normal as the user is not logged in

Binyamin
16 Feb, 2024, 14:56

You should catch it

sanujitmajhi 🐻 ⛓
16 Feb, 2024, 14:56

can i sahre the auth service code

Binyamin
16 Feb, 2024, 14:56

Sure

sanujitmajhi 🐻 ⛓
16 Feb, 2024, 14:57

import { Client, Account,ID } from "appwrite";

import conf from "../conf/conf";

// Create a class for Appwrite client export class Authservice { client = new Client(); account; constructor() {

TypeScript
    this.client.setEndpoint(conf.appwriteurl)
       .setProject(conf.appwriteProjectid);
    this.account=new Account(this.client)

}

async signup({email, password,name}) {
    try {
        // Use the Appwrite Account API to create a new user
        const useraccount=await this.account.create(ID.unique(),email, password,name);

        if (useraccount) {

              return this.login({email,password})

            
        } 
        else {
             return useraccount
            
        }




    } catch (error) {
        console.error('Error during signup:', error);
    }
}

async login({email, password}) {
    try {
        return await this.account.createEmailSession(email, password);
        


    } catch (error) {
        console.error('Error during login:', error);
    }
}

async  is_loggedin(){

    try {

         return await this.account.get();
        
    } catch (error) {
         
        console.log('you corresponding appwrite error is:',error)
        
    }


    return null;


}


async logout(){

    try {

        this.account.deleteSessions();
        
    } catch (error) {
        console.log('you corresponding appwrite error is:',error)
        
    }

}


async getcurrentuser(){

         try {
              const loggeddin=await this.account.get()
              return loggeddin
            
         } catch (error) {
             console.log(error)

             return null
            
         }

}
sanujitmajhi 🐻 ⛓
16 Feb, 2024, 14:57

}

// Create an instance of AppwriteClient const authservice = new Authservice();

export default authservice;

Binyamin
16 Feb, 2024, 14:57

This is good

Binyamin
16 Feb, 2024, 14:57

Which console.log is the error you're getting?

sanujitmajhi 🐻 ⛓
16 Feb, 2024, 14:58

AppwriteException: User (role: guests) missing scope (account) at Client.<anonymous> (http://localhost:5173/node_modules/.vite/deps/appwrite.js?v=5dc19954:850:17) at Generator.next (<anonymous>) at fulfilled (http://localhost:5173/node_modules/.vite/deps/appwrite.js?v=5dc19954:488:24)

sanujitmajhi 🐻 ⛓
16 Feb, 2024, 14:58

here this one

Binyamin
16 Feb, 2024, 14:59

But from which one

TypeScript
  async getcurrentuser(){
             try {
                  const loggeddin=await this.account.get()
                  return loggeddin

             } catch (error) {
                 console.log(error)

                 return null
             }
    }
Binyamin
16 Feb, 2024, 14:59

Like here for example The error is normal

sanujitmajhi 🐻 ⛓
16 Feb, 2024, 14:59

which one

Binyamin
16 Feb, 2024, 15:00

The error you're getting means that the user is not logged in when you're trying to get the user

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