Skip to content

A local-first personal finance app

[AI] Fix password login broken when OIDC is enabled (#7334)

Matiss Janis Aboltinsc0c2d1630ede
diff --git a/packages/sync-server/src/account-db.js b/packages/sync-server/src/account-db.js
index b15eefebbe..0b6b4419c2 100644
--- a/packages/sync-server/src/account-db.js
+++ b/packages/sync-server/src/account-db.js
@@ -60,11 +60,10 @@ export function getLoginMethod(req) {
config.get('allowedLoginMethods').includes(req.body.loginMethod)
) {
const accountDb = getAccountDb();
- const activeRow = accountDb.first(
- 'SELECT method FROM auth WHERE method = ? AND active = 1',
- [req.body.loginMethod],
- );
- if (activeRow) return req.body.loginMethod;
+ const row = accountDb.first('SELECT method FROM auth WHERE method = ?', [
+ req.body.loginMethod,
+ ]);
+ if (row) return req.body.loginMethod;
}
//BY-PASS ANY OTHER CONFIGURATION TO ENSURE HEADER AUTH
diff --git a/packages/sync-server/src/app-account.test.js b/packages/sync-server/src/app-account.test.js
index 8a55d1fdde..5608d49bf9 100644
--- a/packages/sync-server/src/app-account.test.js
+++ b/packages/sync-server/src/app-account.test.js
@@ -154,11 +154,11 @@ describe('getLoginMethod()', () => {
expect(getLoginMethod(req)).toBe('openid');
});
- it('ignores a client-requested method that is inactive in DB', () => {
+ it('honors a client-requested method that exists but is inactive in DB', () => {
insertAuthRow('openid', 1);
insertAuthRow('password', 0);
const req = { body: { loginMethod: 'password' } };
- expect(getLoginMethod(req)).toBe('openid');
+ expect(getLoginMethod(req)).toBe('password');
});
it('ignores a client-requested method that is not in DB', () => {
@@ -174,6 +174,43 @@ describe('getLoginMethod()', () => {
});
});
+describe('/login', () => {
+ afterEach(() => {
+ clearAuth();
+ });
+
+ it('should allow password login when OIDC is the active method', async () => {
+ bootstrapPassword('testpassword');
+ insertAuthRow('openid', 1);
+ getAccountDb().mutate(
+ "UPDATE auth SET active = 0 WHERE method = 'password'",
+ );
+
+ const res = await request(app)
+ .post('/login')
+ .send({ loginMethod: 'password', password: 'testpassword' });
+
+ expect(res.statusCode).toEqual(200);
+ expect(res.body).toHaveProperty('status', 'ok');
+ expect(res.body.data).toHaveProperty('token');
+ });
+
+ it('should reject wrong password even when method is explicitly requested', async () => {
+ bootstrapPassword('testpassword');
+ insertAuthRow('openid', 1);
+ getAccountDb().mutate(
+ "UPDATE auth SET active = 0 WHERE method = 'password'",
+ );
+
+ const res = await request(app)
+ .post('/login')
+ .send({ loginMethod: 'password', password: 'wrongpassword' });
+
+ expect(res.statusCode).toEqual(400);
+ expect(res.body).toHaveProperty('reason', 'invalid-password');
+ });
+});
+
describe('/server-prefs', () => {
describe('POST /server-prefs', () => {
let adminUserId, basicUserId, adminSessionToken, basicSessionToken;
diff --git a/upcoming-release-notes/7334.md b/upcoming-release-notes/7334.md
new file mode 100644
index 0000000000..60727a1198
--- /dev/null
+++ b/upcoming-release-notes/7334.md
@@ -0,0 +1,6 @@
+---
+category: Bugfixes
+authors: [MatissJanis]
+---
+
+Fix password login functionality when OIDC is enabled, ensuring proper authentication method handling.