#Cannot delete account using appwrite auth

1 messages · Page 1 of 1 (latest)

tame lark
#

other things working well, but my delete isn't working :

deleteAccount: async (password: string) => {
try {
// First, delete all active sessions
try {
const sessions = await account.listSessions();
for (const session of sessions.sessions) {
await account.deleteSession(session.$id);
}
} catch (error) {
console.log('No sessions to delete');
}

        // Verify credentials by creating a temporary session
        const user = await account.get();
        await account.createEmailPasswordSession(user.email, password);
        
        // Now delete the account
        await account.delete();
        
        return true;
    } catch (error) {
        console.error('Delete account error:', error);
        throw error;
    }
},
dusty dew
#

whats the error?

tame lark
#

(NOBRIDGE) ERROR Delete account error: [AppwriteException: User (role: guests) missing scope (account)]

#

@dusty dew

dusty dew
tame lark
#

when i remove that i get Delete account error: [AppwriteException: Creation of a session is prohibited when a session is active.]

#

is it because deletion must happen from server side

jovial fern
#

The last error indicates that there is already an active session, so a new one cannot be created. You can add a conditional structure after the line where you fetch the existing user and check if they already exist. If not, you can create a new session. I believe this will resolve the issue