Fixed automated code review warnings
This commit is contained in:
@@ -14,7 +14,7 @@ async function login(request: UnwrappedRequest): Promise<Response> {
|
|||||||
refreshCount: string;
|
refreshCount: string;
|
||||||
} | null = await orm.users.verifyCredentials(requestBody.username, requestBody.password);
|
} | null = await orm.users.verifyCredentials(requestBody.username, requestBody.password);
|
||||||
if (!verify) {
|
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.
|
// 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 cookies = request.request.cookies;
|
||||||
const refreshCookie = cookies.get('refresh');
|
const refreshCookie = cookies.get('refresh');
|
||||||
if (!refreshCookie) {
|
if (!refreshCookie) {
|
||||||
throw new UnauthorizedError('No refresh token found');
|
return new UnauthorizedResponse('No refresh token found');
|
||||||
}
|
}
|
||||||
|
|
||||||
const refreshToken: {
|
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 {
|
try {
|
||||||
const response = new OkResponse();
|
const response = new OkResponse();
|
||||||
response.headers.set('Clear-Site-Data', '"cookies","cache","storage","executionContexts"');
|
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 {
|
try {
|
||||||
const requestBody = request.body as ChangePasswordRequest;
|
|
||||||
return new OkResponse(
|
return new OkResponse(
|
||||||
await orm.users.changePassword(
|
await orm.users.changePassword(
|
||||||
SecureId.fromHash(request.params.id),
|
SecureId.fromHash(request.params.id),
|
||||||
requestBody.oldPassword,
|
request.body.oldPassword,
|
||||||
requestBody.newPassword,
|
request.body.newPassword,
|
||||||
request.claims,
|
request.claims,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ const server = Bun.serve({
|
|||||||
...player,
|
...player,
|
||||||
...game,
|
...game,
|
||||||
'/test': {
|
'/test': {
|
||||||
GET: (request) => {
|
GET: () => {
|
||||||
return new OkResponse();
|
return new OkResponse();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Claims } from './claims';
|
import { Claims } from './claims';
|
||||||
import { sql } from 'bun';
|
import { sql } from 'bun';
|
||||||
import { first, memoize } from 'lodash';
|
import { first } from 'lodash';
|
||||||
import { NotFoundError, UnauthorizedError } from '../utilities/errors';
|
import { NotFoundError, UnauthorizedError } from '../utilities/errors';
|
||||||
import { CreateGameRequest, SecureId, UpdateGameRequest } from '../utilities/requestModels';
|
import { CreateGameRequest, SecureId, UpdateGameRequest } from '../utilities/requestModels';
|
||||||
import { memo } from '../utilities/helpers';
|
import { memo } from '../utilities/helpers';
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Claims } from './claims';
|
import { Claims } from './claims';
|
||||||
import { sql } from 'bun';
|
import { sql } from 'bun';
|
||||||
import { first } from 'lodash';
|
import { first } from 'lodash';
|
||||||
import { BadRequestError, NotFoundError, UnauthorizedError } from '../utilities/errors';
|
import { NotFoundError, UnauthorizedError } from '../utilities/errors';
|
||||||
import { orm } from './orm';
|
import { orm } from './orm';
|
||||||
import { SecureId, UpdatePlayerRequest } from '../utilities/requestModels';
|
import { SecureId, UpdatePlayerRequest } from '../utilities/requestModels';
|
||||||
|
|
||||||
@@ -74,11 +74,7 @@ export class PlayersOrm {
|
|||||||
|
|
||||||
async update(
|
async update(
|
||||||
id: SecureId,
|
id: SecureId,
|
||||||
patch: {
|
patch: UpdatePlayerRequest,
|
||||||
name?: string;
|
|
||||||
isRatingLocked?: boolean;
|
|
||||||
canBeMultiple?: boolean;
|
|
||||||
},
|
|
||||||
claims?: Claims,
|
claims?: Claims,
|
||||||
): Promise<Player | null> {
|
): Promise<Player | null> {
|
||||||
if (!(Claims.test(Claims.ADMIN, claims) || Claims.test(Claims.PLAYERS.OTHER.UPDATE, claims))) {
|
if (!(Claims.test(Claims.ADMIN, claims) || Claims.test(Claims.PLAYERS.OTHER.UPDATE, claims))) {
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ export class UsersOrm {
|
|||||||
|
|
||||||
async update(
|
async update(
|
||||||
id: SecureId,
|
id: SecureId,
|
||||||
patch: { isActive?: boolean; isAdmin?: boolean },
|
patch: UpdateUserRequest,
|
||||||
claims?: Claims,
|
claims?: Claims,
|
||||||
): Promise<User | null> {
|
): Promise<User | null> {
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export function guard(
|
|||||||
try {
|
try {
|
||||||
const userClaims: Claims = jwt.verify(authHeader as string, process.env.JWT_SECRET_KEY as string) as Claims;
|
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))) {
|
if (!userClaims.claims.some((x: string): boolean => guardedClaims.includes(x))) {
|
||||||
throw new UnauthorizedError('Unauthorized');
|
return new UnauthorizedResponse('Unauthorized');
|
||||||
}
|
}
|
||||||
return method(await unwrap(request, userClaims));
|
return method(await unwrap(request, userClaims));
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { BadRequestError, NotFoundError, UnauthorizedError } from './errors';
|
import { BadRequestError, NotFoundError, UnauthorizedError } from './errors';
|
||||||
import { hashIds } from './guard';
|
|
||||||
|
|
||||||
export class ErrorResponse extends Response {
|
export class ErrorResponse extends Response {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
|
|||||||
Reference in New Issue
Block a user