Back

Having trouble getting the Session for Logout

  • 0
  • Databases
  • Cloud
Mr English
10 Jun, 2024, 18:21

I am building a logout script. It generates this error:

throw new AppwriteException(data === null || data === void 0 ? void 0 : data.message, response.status, data === null || data === void 0 ? void 0 : data.type, data); ^ AppwriteException: User (role: guests) missing scope (account)

I have confirmed that I am logged in and there is a session in the Appwrite - Auth - User - sessions table I have indicated where the error message is generated. This approach is from the documentation. I am implementing Client SDK. Can someone tell me what I am doing wrong. Thanks.

TypeScript
exports.logout = async (req,res) => {

    const { Client, Account } = require("appwrite");

    const client = new Client()
        .setEndpoint('https://cloud.appwrite.io/v1') 
        .setProject(process.env.PROJECT_ID); 

    const account = new Account(client);
    const currentSession = await account.getSession('current'); // <--- error message is generated here
    console.log(currentSession)

    const logout = async () => {
        const acc= await account.deleteSession("current");
        setLoggedInUser(null);
    };

    console.log(logout)

    res.render('logout');
}
TL;DR
Developers are having trouble with a logout script due to 'User (role: guests) missing scope (account)' error. The issue stems from attempting to get the session. A potential solution involves ensuring proper authentication and session handling within the Client SDK implementation.
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