diff --git a/leaky-ships/lib/backend/errors.ts b/leaky-ships/lib/backend/errors.ts index 5f4f6d3..654386e 100644 --- a/leaky-ships/lib/backend/errors.ts +++ b/leaky-ships/lib/backend/errors.ts @@ -11,56 +11,9 @@ interface rejectionErrors { } export const rejectionErrors: rejectionErrors = { - noCookie: { - message: "Unauthorized. No cookie.", - statusCode: 401, - solved: true, - }, - noBody: { - message: "Unauthorized. No Body.", - statusCode: 401, - solved: true, - type: ["warn"], - }, - noUsername: { - message: "No username in request body!", - statusCode: 401, - solved: true, - type: ["warn"], - }, - noPassword: { - message: "No password in request body!", - statusCode: 401, - solved: true, - type: ["warn"], - }, - wrongPassword: { - message: "Passwords do not match!", - statusCode: 401, - solved: true, - type: ["warn"], - }, - playerNotFound: { - message: "Player name not found in DB!", - statusCode: 401, - solved: false, - type: ["warn"], - }, - tokenUsed: { - message: "DBToken was already used!", - statusCode: 401, - solved: true, - type: ["warn"], - }, - registered: { - message: "Player is already registered!", - statusCode: 403, - solved: true, - type: ["warn"], - }, gameNotFound: { message: "Game not found!", - statusCode: 403, + statusCode: 404, solved: true, }, unauthorized: { diff --git a/leaky-ships/lib/backend/getPinFromBody.ts b/leaky-ships/lib/backend/getPinFromBody.ts index cfbf2d9..495da97 100644 --- a/leaky-ships/lib/backend/getPinFromBody.ts +++ b/leaky-ships/lib/backend/getPinFromBody.ts @@ -10,11 +10,10 @@ async function getPinFromBody(req: NextApiRequest, res: NextApiResponse) { typeof body.pin !== "string" ) throw sendError(req, res, { - rejected: true, message: "No pin in request body!", statusCode: 401, solved: true, - type: "warn", + type: ["warn"], }) const { pin } = body diff --git a/leaky-ships/lib/backend/jwtVerifyCatch.ts b/leaky-ships/lib/backend/jwtVerifyCatch.ts deleted file mode 100644 index 723edc3..0000000 --- a/leaky-ships/lib/backend/jwtVerifyCatch.ts +++ /dev/null @@ -1,40 +0,0 @@ -import type { rejectionError } from "./errors" -import type { TokenType } from "@prisma/client" - -export default function jwtVerifyCatch( - tokenType: TokenType, - err: Error -): rejectionError { - switch (err.message) { - case "jwt expired": - return { - message: `JWT (${tokenType}) expired!`, - statusCode: 403, - solved: true, - type: "warn", - } - - case "invalid signature": - return { - message: `Invalid JWT (${tokenType}) signature! Token: `, - statusCode: 401, - solved: false, - } - - case "jwt must be provided": - return { - message: `No JWT (${tokenType}) given.`, - statusCode: 401, - solved: true, - type: "warn", - } - - default: - console.log(err) - return { - statusCode: 500, - message: `Unknown error on 'JWT.verify()'.`, - solved: false, - } - } -} diff --git a/leaky-ships/lib/backend/sendError.ts b/leaky-ships/lib/backend/sendError.ts index d1d7393..36391d5 100644 --- a/leaky-ships/lib/backend/sendError.ts +++ b/leaky-ships/lib/backend/sendError.ts @@ -1,5 +1,5 @@ -import type { rejectionError } from "../errors" -import logging from "../logging" +import { rejectionError } from "./errors" +import logging from "./logging" import type { NextApiRequest, NextApiResponse } from "next" export default function sendError( @@ -12,7 +12,7 @@ export default function sendError( logging( err.message, "type" in err && err.type - ? [err.type] + ? err.type : ["solved" in err && err.solved ? "debug" : "error"], req ) diff --git a/leaky-ships/pages/gamefield.tsx b/leaky-ships/pages/gamefield.tsx index eece6bb..95f5dd0 100644 --- a/leaky-ships/pages/gamefield.tsx +++ b/leaky-ships/pages/gamefield.tsx @@ -1,4 +1,4 @@ -import Gamefield from "../../components/Gamefield/Gamefield" +import Gamefield from "../components/Gamefield/Gamefield" import Head from "next/head" export default function Home() { diff --git a/leaky-ships/pages/grid.tsx b/leaky-ships/pages/grid.tsx index 9a45a52..4ac99f3 100644 --- a/leaky-ships/pages/grid.tsx +++ b/leaky-ships/pages/grid.tsx @@ -1,4 +1,4 @@ -import Grid from "../../components/Grid" +import Grid from "../components/Grid" import Head from "next/head" export default function Home() { diff --git a/leaky-ships/pages/grid2.tsx b/leaky-ships/pages/grid2.tsx index cd8e5b2..fedca37 100644 --- a/leaky-ships/pages/grid2.tsx +++ b/leaky-ships/pages/grid2.tsx @@ -1,4 +1,4 @@ -import Grid2 from "../../components/Grid2" +import Grid2 from "../components/Grid2" import Head from "next/head" export default function Home() { diff --git a/leaky-ships/pages/lobby.tsx b/leaky-ships/pages/lobby.tsx index 61bb28e..2ae786d 100644 --- a/leaky-ships/pages/lobby.tsx +++ b/leaky-ships/pages/lobby.tsx @@ -1,7 +1,7 @@ -import BurgerMenu from "../../components/BurgerMenu" -import LobbyFrame from "../../components/Lobby/LobbyFrame" -import Settings from "../../components/Lobby/SettingsFrame/Settings" -import Logo from "../../components/Logo" +import BurgerMenu from "../components/BurgerMenu" +import LobbyFrame from "../components/Lobby/LobbyFrame" +import Settings from "../components/Lobby/SettingsFrame/Settings" +import Logo from "../components/Logo" import classNames from "classnames" import Head from "next/head" import { useState } from "react" diff --git a/leaky-ships/pages/socket.tsx b/leaky-ships/pages/socket.tsx index f906ee4..9759892 100644 --- a/leaky-ships/pages/socket.tsx +++ b/leaky-ships/pages/socket.tsx @@ -1,5 +1,4 @@ -import type { ClientToServerEvents, ServerToClientEvents } from "../api/ws" -import getAccessToken from "@lib/frontend/getAccessToken" +import { ClientToServerEvents, ServerToClientEvents } from "./api/ws" import { ChangeEventHandler, useEffect, useState } from "react" import { io, Socket } from "socket.io-client" @@ -20,9 +19,9 @@ const Home = () => { method: "POST", body: JSON.stringify({ username: "warst", password: "warst" }), }) - getAccessToken().then((token) => { - socket.emit("authenticate", { token }) - }) + // getAccessToken().then((token) => { + // socket.emit("authenticate", { token }) + // }) socket.on("connect", () => { console.log("connected")