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
- self-hosted auth: /v1/account 404 on saf...
Project created in React/Next.js, Appwrite version 1.6.0. Authentication works in all browsers except Safari (ios), where an attempt to connect to {endpoint}/v1...
- delete document problems
i don't know what's going on but i get an attribute "tournamentid" not found in the collection when i try to delet the document... but this is just the document...
- Update User Error
```ts const { users, databases } = await createAdminClient(); const session = await getLoggedInUser(); const user = await users.get(session.$id); if (!use...