Skip to content

Commit

Permalink
Enforce user has auth.credentials_login to be able to login
Browse files Browse the repository at this point in the history
Change-type: minor
  • Loading branch information
otaviojacobi committed Jun 5, 2024
1 parent 4c7e5b8 commit 664f24e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/features/auth/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { errors, sbvrUtils } from '@balena/pinejs';
import { comparePassword, findUser } from '../../infra/auth/auth.js';
import { loginUserXHR } from '../../infra/auth/jwt.js';
import { captureException } from '../../infra/error-handling/index.js';
import { permissions } from '@balena/pinejs';

import type { SetupOptions } from '../../index.js';

Expand All @@ -23,6 +24,11 @@ export const login =
if (!user) {
throw new NotFoundError('User not found.');
}
const userPermissions = await permissions.getUserPermissions(user.id);

if (!userPermissions.includes('auth.credentials_login')) {
throw new BadRequestError('User not allowed to login.');
}

const matches = await comparePassword(password, user.password);
if (!matches) {
Expand Down

0 comments on commit 664f24e

Please sign in to comment.