Appwrite serive :: getCurrentUser :: error AppwriteException: User (role: guests) missing scope
- 0
- Web

hello, I have got this error when using 'account. get();' this method. I have provided the error msg and code can you help me with any more information you need I will provide it.
CODE Auth.js
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 }) {
// eslint-disable-next-line no-useless-catch
try {
const userAccount = await this.account.create(
ID.unique(),
email,
password,
name
);
if (userAccount) {
// call another mwthod
return this.login({ email, password });
} else {
// throw new Error("Failed to create user account");
return userAccount;
}
} catch (error) {
throw error;
}
}
async login({ email, password }) {
// eslint-disable-next-line no-useless-catch
try {
return await this.account.createSession(email, password);
} catch (error) {
throw error;
}
}
async getCurrentUser() {
// eslint-disable-next-line no-useless-catch
try {
return await this.account.get();
} catch (error) {
console.log("Appwrite serive :: getCurrentUser :: error", error);
return null;
}
}
async logout(){
// eslint-disable-next-line no-useless-catch
try {
await this.account.deleteSessions();
} catch (error) {
throw error;
}
}
}
const authService = new AuthService();
export default authService;
/```

Which version of the SDK are you using?

not use SDK

"appwrite": "^14.0.1", in node

If you're trying to login using email/password, you'll want to use createEmailPasswordSession()
instead of createSession()
https://appwrite.io/docs/references/cloud/client-web/account#createEmailPasswordSession

This looks like it's the issue as it's never actually logging the user in

import { useEffect, useState } from 'react'; import './App.css'; import { useDispatch } from 'react-redux'; import authService from './appwrit/auth'; import { login, logout } from './store/authSlice'; import { Footer, Header } from './components'; import { Outlet } from 'react-router-dom';
function App() { const [loading, setLoading] = useState(true); const dispatch = useDispatch();
useEffect(() => { authService.getCurrentUser() .then((userData) => { if (userData) { dispatch(login({userData})) } else { dispatch(logout()) } }) .finally(() => setLoading(false)) }, [])
return !loading ? ( <div className='w-full min-h-screen flex flex-wrap content-baseline bg-slate-400'> <div className='w-full block'> <Header /> <main> <Outlet /> </main> <Footer /> </div> </div> ) : ( <div className='w-full min-h-screen flex justify-center items-center bg-slate-400'> <p>Loading...</p> </div> )
}
export default App;

this is my App.jsx
Recommended threads
- Need help setting up this error is showi...
You can't sign in to this app because it doesn't comply with Google's OAuth 2.0 policy. If you're the app developer, register the redirect URI in the Google Cl...
- Appwrite stopped working, I can't authen...
I'm having an issue with Appwrite. It was working fine just a while ago, but suddenly it stopped working for me and can't authenticate accounts. I even went bac...
- Fail to receive the verification email a...
I added my email address to prevent it from showing "appwrite," but now I'm not receiving emails for verification or password resets. The function appears to be...
