diff --git a/src/account-db.js b/src/account-db.js index c8c30bf0b..c7fff76ed 100644 --- a/src/account-db.js +++ b/src/account-db.js @@ -169,9 +169,25 @@ export async function disableOpenID(loginSettings) { return { error }; } - getAccountDb().mutate('DELETE FROM sessions'); - getAccountDb().mutate('DELETE FROM users WHERE user_name <> ?', ['']); - getAccountDb().mutate('DELETE FROM auth WHERE method = ?', ['openid']); + try { + accountDb.transaction(() => { + accountDb.mutate('DELETE FROM sessions'); + accountDb.mutate( + `DELETE FROM user_access + WHERE user_access.user_id IN ( + SELECT users.id + FROM users + WHERE users.user_name <> ? + );`, + [''], + ); + accountDb.mutate('DELETE FROM users WHERE user_name <> ?', ['']); + accountDb.mutate('DELETE FROM auth WHERE method = ?', ['openid']); + }); + } catch (err) { + console.error('Error cleaning up openid information:', err); + return { error: 'database-error' }; + } } export function getSession(token) { diff --git a/src/scripts/enable-openid.js b/src/scripts/enable-openid.js index 8007d9cdb..caf782ff1 100644 --- a/src/scripts/enable-openid.js +++ b/src/scripts/enable-openid.js @@ -25,10 +25,19 @@ if (needsBootstrap()) { if (error) { console.log('Error enabling openid:', error); - console.log( - 'Please report this as an issue: https://github.com/actualbudget/actual-server/issues', - ); - process.exit(2); + if (error === 'invalid-login-settings') { + console.log( + 'Error configuring OpenID. Please verify that the configuration file or environment variables are correct.', + ); + + process.exit(1); + } else { + console.log( + 'Please report this as an issue: https://github.com/actualbudget/actual-server/issues', + ); + + process.exit(2); + } } console.log('OpenID enabled!'); console.log(