Fixed automated code review warnings

This commit is contained in:
jd
2026-02-18 21:36:27 +00:00
parent 2996a2eb95
commit 035397ea25
7 changed files with 13 additions and 19 deletions

View File

@@ -14,7 +14,7 @@ async function login(request: UnwrappedRequest): Promise<Response> {
refreshCount: string;
} | null = await orm.users.verifyCredentials(requestBody.username, requestBody.password);
if (!verify) {
throw new UnauthorizedError('Invalid credentials');
return new UnauthorizedResponse('Invalid credentials');
}
// Build refresh token that expires in 30 days, return as secure HTTP only cookie.
@@ -46,7 +46,7 @@ async function token(request: UnwrappedRequest): Promise<Response> {
const cookies = request.request.cookies;
const refreshCookie = cookies.get('refresh');
if (!refreshCookie) {
throw new UnauthorizedError('No refresh token found');
return new UnauthorizedResponse('No refresh token found');
}
const refreshToken: {
@@ -69,7 +69,7 @@ async function token(request: UnwrappedRequest): Promise<Response> {
}
}
async function logout(request: UnwrappedRequest): Promise<Response> {
async function logout(): Promise<Response> {
try {
const response = new OkResponse();
response.headers.set('Clear-Site-Data', '"cookies","cache","storage","executionContexts"');
@@ -79,14 +79,13 @@ async function logout(request: UnwrappedRequest): Promise<Response> {
}
}
async function changePassword(request: UnwrappedRequest): Promise<Response> {
async function changePassword(request: UnwrappedRequest<ChangePasswordRequest>): Promise<Response> {
try {
const requestBody = request.body as ChangePasswordRequest;
return new OkResponse(
await orm.users.changePassword(
SecureId.fromHash(request.params.id),
requestBody.oldPassword,
requestBody.newPassword,
request.body.oldPassword,
request.body.newPassword,
request.claims,
),
);

View File

@@ -11,7 +11,7 @@ const server = Bun.serve({
...player,
...game,
'/test': {
GET: (request) => {
GET: () => {
return new OkResponse();
},
},

View File

@@ -1,6 +1,6 @@
import { Claims } from './claims';
import { sql } from 'bun';
import { first, memoize } from 'lodash';
import { first } from 'lodash';
import { NotFoundError, UnauthorizedError } from '../utilities/errors';
import { CreateGameRequest, SecureId, UpdateGameRequest } from '../utilities/requestModels';
import { memo } from '../utilities/helpers';

View File

@@ -1,7 +1,7 @@
import { Claims } from './claims';
import { sql } from 'bun';
import { first } from 'lodash';
import { BadRequestError, NotFoundError, UnauthorizedError } from '../utilities/errors';
import { NotFoundError, UnauthorizedError } from '../utilities/errors';
import { orm } from './orm';
import { SecureId, UpdatePlayerRequest } from '../utilities/requestModels';
@@ -74,11 +74,7 @@ export class PlayersOrm {
async update(
id: SecureId,
patch: {
name?: string;
isRatingLocked?: boolean;
canBeMultiple?: boolean;
},
patch: UpdatePlayerRequest,
claims?: Claims,
): Promise<Player | null> {
if (!(Claims.test(Claims.ADMIN, claims) || Claims.test(Claims.PLAYERS.OTHER.UPDATE, claims))) {

View File

@@ -92,7 +92,7 @@ export class UsersOrm {
async update(
id: SecureId,
patch: { isActive?: boolean; isAdmin?: boolean },
patch: UpdateUserRequest,
claims?: Claims,
): Promise<User | null> {
if (

View File

@@ -29,7 +29,7 @@ export function guard(
try {
const userClaims: Claims = jwt.verify(authHeader as string, process.env.JWT_SECRET_KEY as string) as Claims;
if (!userClaims.claims.some((x: string): boolean => guardedClaims.includes(x))) {
throw new UnauthorizedError('Unauthorized');
return new UnauthorizedResponse('Unauthorized');
}
return method(await unwrap(request, userClaims));
} catch (error: any) {

View File

@@ -1,5 +1,4 @@
import { BadRequestError, NotFoundError, UnauthorizedError } from './errors';
import { hashIds } from './guard';
export class ErrorResponse extends Response {
//@ts-ignore