Skip to content

Do not fail auto-login when authentication token is invalid

Milian Wolff requested to merge work/dont-fail-autologin into master

Starting ruqola after some day, I am usually seeing login failures for all my servers. The reason is that I'm too slow to unlock my kwallet keychain, and thus no password is yet available. If that happens when the authentication token is invalid, then we tried to login with an empty password which is bound to fail. This patch prevents this from happening and instead updates the password prompt once we read it from the keychain. Then the user can manually click login.

While this is still a bit annoying over a fully automated login in such a scenario, it's less of a hassle than before, where we would see a login page with a login error and an empty password prompt.

To test this manually, you can use this patch and remove the auth token from the ruqola configuration of your server:

diff --git a/src/core/rocketchataccountsettings.cpp b/src/core/rocketchataccountsettings.cpp
index dc5c9cb70..e55dcdbb0 100644
--- a/src/core/rocketchataccountsettings.cpp
+++ b/src/core/rocketchataccountsettings.cpp
@@ -14,6 +14,7 @@
 #include <QFile>
 #include <QSettings>
 #include <QStandardPaths>
+#include <QTimer>
 #include <qt5keychain/keychain.h>
(1/2) Discard this hunk from worktree [y,n,q,a,d,j,J,g,/,e,?]? y
@@ -62,9 +63,13 @@ void RocketChatAccountSettings::slotPasswordRead(QKeychain::Job *baseJob)
     auto job = qobject_cast<ReadPasswordJob *>(baseJob);
     if (!job->error()) {
-        mPassword = job->textData();
-        qCDebug(RUQOLA_LOG) << "OK, we have the password now";
-        Q_EMIT passwordChanged();
+        auto p = job->textData();
+        QTimer::singleShot(1000, this, [this, p]() {
+            qWarning() << p;
+            mPassword = p;
+            qCDebug(RUQOLA_LOG) << "OK, we have the password now";
+            Q_EMIT passwordChanged();
+        });
     } else {
         qCWarning(RUQOLA_LOG) << "We have an error during reading password " << job->errorString() << " Account name " << mAccountName;
(2/2) Discard this hunk from worktree [y,n,q,a,d,K,g,/,e,?]?

Merge request reports