Skip to content

Commit aefe69e

Browse files
committed
fix(auth): enhance dashboard login security
- Added role verification for dashboard logins. - Prevents non-admin access via code verification. - Improved security against unauthorized access. - Closed loophole in existing authentication flow. - Added logging for successful/failed verifications.
1 parent b7f1a22 commit aefe69e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lib/src/services/auth_service.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,25 @@ class AuthService {
157157
final existingUser = await _findUserByEmail(email);
158158
if (existingUser != null) {
159159
user = existingUser;
160+
// If this is a dashboard login, re-verify the user's dashboard role.
161+
// This closes the loophole where a non-admin user could request a code
162+
// via the app flow and then use it to log into the dashboard.
163+
if (isDashboardLogin) {
164+
final hasRequiredRole =
165+
user.dashboardRole == DashboardUserRole.admin ||
166+
user.dashboardRole == DashboardUserRole.publisher;
167+
168+
if (!hasRequiredRole) {
169+
_log.warning(
170+
'Dashboard login failed: User ${user.id} lacks required roles '
171+
'during code verification.',
172+
);
173+
throw const ForbiddenException(
174+
'Your account does not have the required permissions to sign in.',
175+
);
176+
}
177+
_log.info('Dashboard user ${user.id} re-verified successfully.');
178+
}
160179
} else {
161180
// User not found.
162181
if (isDashboardLogin) {

0 commit comments

Comments
 (0)