Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AppwriteException: User (role: guests) missing scope (account) ReactJS application #5735

Closed
ghost opened this issue Jun 21, 2023 · 1 comment

Comments

@ghost
Copy link

ghost commented Jun 21, 2023

How do I solve this error ?
GET https://cloud.appwrite.io/v1/account/sessions/current 401
Failed to load resource: the server responded with a status of 401 ()

import React, { useEffect,useState } from 'react'
import { createContext,useContext } from 'react'
import { account } from './appwrite'
const UserContext=createContext()
const UserProvider = ({children}) => {
   const [currentUser,setCurrentUser]=useState('')
   const [sessionId,setSessionId]=useState('')
    const logout=()=>{
        const promise=account.deleteSession(sessionId)
        promise.then(res=>{
            setSessionId('')
            setCurrentUser('')
        }).catch(err=>{
            console.log(err)
        })
    }
    useEffect(()=>{
        try {
            const _session=account.getSession('current')
            _session.then(res=>{
                setSessionId(res['$id'])
                const promise=account.get()
                promise.then(res=>{
                    setCurrentUser(res)
                }).catch(err=>{
                    console.log(err);      
                })
            }).catch(err=>{              Error is here in the code
                console.log(err);   // AppwriteException: User (role: guests) missing scope (account) 
            })
        } catch (error) {
            console.log(error);
        }
    })
  return (
    <UserContext.Provider value={{
        currentUser,
        setCurrentUser,
        sessionId,
        setSessionId,
        logout
    }}>
{children}
    </UserContext.Provider>
  )
}
export const useUserContext=()=>{
    return useContext(UserContext);
}



export default UserProvider 
@zaidshaikh75
Copy link

Did you find the solution?

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant