Frontend creating a game lobby
This commit is contained in:
parent
8cf563ed92
commit
06f0eacc78
3 changed files with 13 additions and 13 deletions
|
@ -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()
|
||||
|
|
|
@ -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"],
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue