Fix compile errors
This commit is contained in:
parent
da53662d6e
commit
207cf47c10
9 changed files with 16 additions and 105 deletions
|
@ -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: {
|
||||
|
|
|
@ -10,11 +10,10 @@ async function getPinFromBody<T>(req: NextApiRequest, res: NextApiResponse<T>) {
|
|||
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
|
||||
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<T>(
|
||||
|
@ -12,7 +12,7 @@ export default function sendError<T>(
|
|||
logging(
|
||||
err.message,
|
||||
"type" in err && err.type
|
||||
? [err.type]
|
||||
? err.type
|
||||
: ["solved" in err && err.solved ? "debug" : "error"],
|
||||
req
|
||||
)
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import Grid from "../../components/Grid"
|
||||
import Grid from "../components/Grid"
|
||||
import Head from "next/head"
|
||||
|
||||
export default function Home() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import Grid2 from "../../components/Grid2"
|
||||
import Grid2 from "../components/Grid2"
|
||||
import Head from "next/head"
|
||||
|
||||
export default function Home() {
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue