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() {
|
async function getAccessToken() {
|
||||||
const response = await fetch("/api/auth", {
|
const response = await fetch("/api/user/auth", {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
})
|
})
|
||||||
const res = await response.json()
|
const res = await response.json()
|
||||||
|
|
|
@ -39,12 +39,8 @@ export default async function create(
|
||||||
players: true,
|
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
|
return sendResponse(context, {
|
||||||
|
|
||||||
sendResponse(context, {
|
|
||||||
message: `Player: ${player.id} created game: ${game.id}`,
|
message: `Player: ${player.id} created game: ${game.id}`,
|
||||||
body: { game },
|
body: { game },
|
||||||
type: ["debug", "infoCyan"],
|
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 { faCirclePlay } from "@fortawesome/pro-thin-svg-icons"
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
|
||||||
import getAccessToken from "@lib/frontend/getAccessToken"
|
import getAccessToken from "@lib/frontend/getAccessToken"
|
||||||
|
import { useRouter } from "next/router"
|
||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
|
const router = useRouter()
|
||||||
const [heWantsToPlay, setHeWantsToPlay] = useState<boolean | null>(false)
|
const [heWantsToPlay, setHeWantsToPlay] = useState<boolean | null>(false)
|
||||||
return (
|
return (
|
||||||
<div className="h-full bg-theme">
|
<div className="h-full bg-theme">
|
||||||
|
@ -40,13 +42,15 @@ export default function Home() {
|
||||||
</button>
|
</button>
|
||||||
<div className="flex flex-col items-center gap-6 sm:gap-12">
|
<div className="flex flex-col items-center gap-6 sm:gap-12">
|
||||||
<OptionButton
|
<OptionButton
|
||||||
action={() =>
|
action={async () => {
|
||||||
getAccessToken().then((token) =>
|
const token = await getAccessToken()
|
||||||
fetch("/api/create", {
|
const game = await fetch("/api/game/create", {
|
||||||
method: "GET",
|
method: "POST",
|
||||||
})
|
body: JSON.stringify({ token }),
|
||||||
)
|
})
|
||||||
}
|
|
||||||
|
router.push("/dev/lobby")
|
||||||
|
}}
|
||||||
icon={faPlus}
|
icon={faPlus}
|
||||||
>
|
>
|
||||||
Raum erstellen
|
Raum erstellen
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue