mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-01-16 15:12:09 +01:00
refactor: fix biome linting issues and update project documentation
- Fix 36+ biome linting issues reducing errors/warnings from 227 to 191 - Replace explicit 'any' types with proper TypeScript interfaces - Fix React hooks dependencies and useCallback patterns - Resolve unused variables and parameter assignment issues - Improve accessibility with proper label associations - Add comprehensive API documentation for admin and security features - Update README.md with accurate PostgreSQL setup and current tech stack - Create complete documentation for audit logging, CSP monitoring, and batch processing - Fix outdated project information and missing developer workflows
This commit is contained in:
@ -2,6 +2,11 @@ import bcrypt from "bcryptjs";
|
||||
import type { NextAuthOptions } from "next-auth";
|
||||
import CredentialsProvider from "next-auth/providers/credentials";
|
||||
import { prisma } from "./prisma";
|
||||
import {
|
||||
AuditOutcome,
|
||||
createAuditMetadata,
|
||||
securityAuditLogger,
|
||||
} from "./securityAuditLogger";
|
||||
|
||||
// Define the shape of the JWT token for platform users
|
||||
declare module "next-auth/jwt" {
|
||||
@ -47,6 +52,17 @@ export const platformAuthOptions: NextAuthOptions = {
|
||||
},
|
||||
async authorize(credentials) {
|
||||
if (!credentials?.email || !credentials?.password) {
|
||||
await securityAuditLogger.logPlatformAdmin(
|
||||
"platform_login_attempt",
|
||||
AuditOutcome.FAILURE,
|
||||
{
|
||||
metadata: createAuditMetadata({
|
||||
error: "missing_credentials",
|
||||
email: credentials?.email ? "[REDACTED]" : "missing",
|
||||
}),
|
||||
},
|
||||
"Missing email or password for platform login"
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -54,13 +70,55 @@ export const platformAuthOptions: NextAuthOptions = {
|
||||
where: { email: credentials.email },
|
||||
});
|
||||
|
||||
if (!platformUser) return null;
|
||||
if (!platformUser) {
|
||||
await securityAuditLogger.logPlatformAdmin(
|
||||
"platform_login_attempt",
|
||||
AuditOutcome.FAILURE,
|
||||
{
|
||||
metadata: createAuditMetadata({
|
||||
error: "user_not_found",
|
||||
email: "[REDACTED]",
|
||||
}),
|
||||
},
|
||||
"Platform user not found"
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
const valid = await bcrypt.compare(
|
||||
credentials.password,
|
||||
platformUser.password
|
||||
);
|
||||
if (!valid) return null;
|
||||
|
||||
if (!valid) {
|
||||
await securityAuditLogger.logPlatformAdmin(
|
||||
"platform_login_attempt",
|
||||
AuditOutcome.FAILURE,
|
||||
{
|
||||
platformUserId: platformUser.id,
|
||||
metadata: createAuditMetadata({
|
||||
error: "invalid_password",
|
||||
email: "[REDACTED]",
|
||||
role: platformUser.role,
|
||||
}),
|
||||
},
|
||||
"Invalid password for platform login"
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Log successful platform authentication
|
||||
await securityAuditLogger.logPlatformAdmin(
|
||||
"platform_login_success",
|
||||
AuditOutcome.SUCCESS,
|
||||
{
|
||||
platformUserId: platformUser.id,
|
||||
metadata: createAuditMetadata({
|
||||
role: platformUser.role,
|
||||
name: platformUser.name,
|
||||
}),
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
id: platformUser.id,
|
||||
|
||||
Reference in New Issue
Block a user