diff --git a/leaky-ships/lib/backend/components/checkPasswordIsValid.ts b/leaky-ships/lib/backend/components/checkPasswordIsValid.ts index 13b4b41..8d0a19d 100644 --- a/leaky-ships/lib/backend/components/checkPasswordIsValid.ts +++ b/leaky-ships/lib/backend/components/checkPasswordIsValid.ts @@ -3,8 +3,8 @@ import sendError, { API } from "./sendError" import type { Player } from "@prisma/client" import bcrypt from "bcrypt" -export default async function checkPasswordIsValid( - context: API, +export default async function checkPasswordIsValid( + context: API, player: Player, password: string, next: () => void diff --git a/leaky-ships/lib/backend/components/checkTokenIsValid.ts b/leaky-ships/lib/backend/components/checkTokenIsValid.ts index 0f48f6c..ff17140 100644 --- a/leaky-ships/lib/backend/components/checkTokenIsValid.ts +++ b/leaky-ships/lib/backend/components/checkTokenIsValid.ts @@ -4,8 +4,8 @@ import type { IdToken, RawToken } from "./createTokenDB" import sendError, { API } from "./sendError" import jwt from "jsonwebtoken" -async function checkTokenIsValid( - context: API, +async function checkTokenIsValid( + context: API, rawToken: RawToken, next: (token: IdToken) => void ) { diff --git a/leaky-ships/lib/backend/components/getPlayerByIdDB.ts b/leaky-ships/lib/backend/components/getPlayerByIdDB.ts index d6ebfe0..af84e59 100644 --- a/leaky-ships/lib/backend/components/getPlayerByIdDB.ts +++ b/leaky-ships/lib/backend/components/getPlayerByIdDB.ts @@ -3,8 +3,8 @@ import { rejectionErrors } from "../errors" import sendError, { API } from "./sendError" import type { Player, Token } from "@prisma/client" -export default async function getPlayerByIdDB( - context: API, +export default async function getPlayerByIdDB( + context: API, tokenDB: Token, next: (player: Player) => void ) { diff --git a/leaky-ships/lib/backend/components/getPlayerByNameDB.ts b/leaky-ships/lib/backend/components/getPlayerByNameDB.ts index b3c3752..a74b35b 100644 --- a/leaky-ships/lib/backend/components/getPlayerByNameDB.ts +++ b/leaky-ships/lib/backend/components/getPlayerByNameDB.ts @@ -3,8 +3,8 @@ import { rejectionErrors } from "../errors" import sendError, { API } from "./sendError" import type { Player } from "@prisma/client" -export default async function getPlayerByNameDB( - context: API, +export default async function getPlayerByNameDB( + context: API, username: string, next: (player: Player) => void ) { diff --git a/leaky-ships/lib/backend/components/getTokenDB.ts b/leaky-ships/lib/backend/components/getTokenDB.ts index 7dba5a7..7263677 100644 --- a/leaky-ships/lib/backend/components/getTokenDB.ts +++ b/leaky-ships/lib/backend/components/getTokenDB.ts @@ -4,8 +4,8 @@ import type { IdToken } from "./createTokenDB" import sendError, { API } from "./sendError" import type { Token } from "@prisma/client" -async function getTokenDB( - context: API, +async function getTokenDB( + context: API, token: IdToken, next: (tokenDB: Token) => void ) { diff --git a/leaky-ships/lib/backend/components/getTokenFromBody.ts b/leaky-ships/lib/backend/components/getTokenFromBody.ts index ca75fd3..4ad43f2 100644 --- a/leaky-ships/lib/backend/components/getTokenFromBody.ts +++ b/leaky-ships/lib/backend/components/getTokenFromBody.ts @@ -2,8 +2,8 @@ import { rejectionErrorFns } from "../errors" import type { RawToken } from "./createTokenDB" import sendError, { API } from "./sendError" -async function getTokenFromBody( - context: API, +async function getTokenFromBody( + context: API, next: (accessToken: RawToken) => void ) { const type = "ACCESS" diff --git a/leaky-ships/lib/backend/components/getTokenFromCookie.ts b/leaky-ships/lib/backend/components/getTokenFromCookie.ts index 325f9fd..62c7337 100644 --- a/leaky-ships/lib/backend/components/getTokenFromCookie.ts +++ b/leaky-ships/lib/backend/components/getTokenFromCookie.ts @@ -2,8 +2,8 @@ import createPlayerDB from "./createPlayerDB" import createTokenDB, { RawToken } from "./createTokenDB" import type { API } from "./sendError" -async function getTokenFromCookie( - context: API, +async function getTokenFromCookie( + context: API, next: (refreshToken: RawToken) => void ) { const type = "REFRESH" diff --git a/leaky-ships/lib/backend/components/getUserFromBody.ts b/leaky-ships/lib/backend/components/getUserFromBody.ts index 577b1d5..39dace9 100644 --- a/leaky-ships/lib/backend/components/getUserFromBody.ts +++ b/leaky-ships/lib/backend/components/getUserFromBody.ts @@ -1,8 +1,8 @@ import { rejectionErrors } from "../errors" import sendError, { API } from "./sendError" -async function getUserFromBody( - context: API, +async function getUserFromBody( + context: API, next: (username: string, password: string) => void ) { const body = JSON.parse(context.req.body) diff --git a/leaky-ships/lib/backend/components/sendError.ts b/leaky-ships/lib/backend/components/sendError.ts index 7fe8134..ab57ab5 100644 --- a/leaky-ships/lib/backend/components/sendError.ts +++ b/leaky-ships/lib/backend/components/sendError.ts @@ -2,12 +2,15 @@ import type { rejectionError } from "../errors" import logging from "../logging" import type { NextApiRequest, NextApiResponse } from "next" -export interface API { +export interface API { req: NextApiRequest - res: NextApiResponse + res: NextApiResponse } -export default function sendError(context: API, err: rejectionError | Error) { +export default function sendError( + context: API, + err: rejectionError | Error +) { const { res, req } = context // If something went wrong, let the client know with status 500 res.status("statusCode" in err ? err.statusCode : 500).end() diff --git a/leaky-ships/lib/backend/components/sendResponse.ts b/leaky-ships/lib/backend/components/sendResponse.ts index f6ad848..a884de3 100644 --- a/leaky-ships/lib/backend/components/sendResponse.ts +++ b/leaky-ships/lib/backend/components/sendResponse.ts @@ -8,7 +8,7 @@ export interface Result { type?: Logging[] } -export default function sendResponse(context: API, result: Result) { +export default function sendResponse(context: API, result: Result) { const { req, res } = context res.status(result.statusCode ?? 200) result.body ? res.json(result.body) : res.end() diff --git a/leaky-ships/lib/backend/components/updatePlayerDB.ts b/leaky-ships/lib/backend/components/updatePlayerDB.ts index 60220d0..f870873 100644 --- a/leaky-ships/lib/backend/components/updatePlayerDB.ts +++ b/leaky-ships/lib/backend/components/updatePlayerDB.ts @@ -3,8 +3,8 @@ import { rejectionErrors } from "../errors" import sendError, { API } from "./sendError" import type { Player, Prisma } from "@prisma/client" -async function updatePlayerDB( - context: API, +async function updatePlayerDB( + context: API, player: Player, data: Prisma.PlayerUpdateInput, next: (updatedPlayer: Player) => void diff --git a/leaky-ships/pages/api/user/login.ts b/leaky-ships/pages/api/user/login.ts index 34046fc..7546478 100644 --- a/leaky-ships/pages/api/user/login.ts +++ b/leaky-ships/pages/api/user/login.ts @@ -53,7 +53,7 @@ export default async function login( ).catch((err) => sendError(context, err)) } -async function preCheck(context: API, next: () => void) { +async function preCheck(context: API, next: () => void) { const { req } = context const oldRefreshToken = req.cookies.token