Frontend creating a game lobby

This commit is contained in:
aronmal 2023-04-11 21:33:25 +02:00
parent 8cf563ed92
commit 06f0eacc78
Signed by: aronmal
GPG key ID: 816B7707426FC612
3 changed files with 13 additions and 13 deletions

View file

@ -1,5 +1,5 @@
async function getAccessToken() {
const response = await fetch("/api/auth", {
const response = await fetch("/api/user/auth", {
method: "GET",
})
const res = await response.json()

View file

@ -39,12 +39,8 @@ export default async function create(
players: true,
},
})
// Generate a random 4-digit code
const code = Math.floor(Math.random() * 10000)
console.log(code) // Output: a random 4-digit code, e.g. 5678
sendResponse(context, {
return sendResponse(context, {
message: `Player: ${player.id} created game: ${game.id}`,
body: { game },
type: ["debug", "infoCyan"],

View file

@ -6,9 +6,11 @@ import { faPlus, faUserPlus } from "@fortawesome/pro-solid-svg-icons"
import { faCirclePlay } from "@fortawesome/pro-thin-svg-icons"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import getAccessToken from "@lib/frontend/getAccessToken"
import { useRouter } from "next/router"
import { useState } from "react"
export default function Home() {
const router = useRouter()
const [heWantsToPlay, setHeWantsToPlay] = useState<boolean | null>(false)
return (
<div className="h-full bg-theme">
@ -40,13 +42,15 @@ export default function Home() {
</button>
<div className="flex flex-col items-center gap-6 sm:gap-12">
<OptionButton
action={() =>
getAccessToken().then((token) =>
fetch("/api/create", {
method: "GET",
})
)
}
action={async () => {
const token = await getAccessToken()
const game = await fetch("/api/game/create", {
method: "POST",
body: JSON.stringify({ token }),
})
router.push("/dev/lobby")
}}
icon={faPlus}
>
Raum erstellen