aboutsummaryrefslogtreecommitdiffstats
path: root/frontend/ts/login.ts
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/ts/login.ts')
-rw-r--r--frontend/ts/login.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/frontend/ts/login.ts b/frontend/ts/login.ts
new file mode 100644
index 0000000..4ef46ab
--- /dev/null
+++ b/frontend/ts/login.ts
@@ -0,0 +1,26 @@
+import startGame from "./startGame.js";
+
+let html = /* html */ `
+ <div class="container text-center fs-1" style="margin-top: 45vh;">
+ <label for="username">Vad heter du?</label>
+ <input type="text" name="username" required>
+ <button type="button" class="btn btn-light btn-lg" onclick="login">Starta spelet</button>
+ </div>
+`;
+
+async function login() {
+ let username = document.getElementsByTagName("input")[0].innerHTML,
+ res = await fetch("/login", {
+ method: "POST",
+ headers: {
+ Accept: "application/json",
+ "Content-Type": "application/json"
+ },
+ body: JSON.stringify({ username: username })
+ });
+ res = await res.json();
+ startGame(res);
+}
+
+document.body.innerHTML = html;
+document.getElementsByTagName("button")[0].onclick = login;