Compare commits
No commits in common. "3b30f11d0f88f4d1bb815e5ff3f7210c6c02b6c0" and "b0b14bc5594ebd3c3e38fca368ef0161c2dddd8f" have entirely different histories.
3b30f11d0f
...
b0b14bc559
@ -1,6 +1,6 @@
|
|||||||
import { A, useNavigate } from "@solidjs/router";
|
import { A } from "@solidjs/router";
|
||||||
import { createSignal, onMount, Show } from "solid-js";
|
import { createSignal, onMount, Show } from "solid-js";
|
||||||
import { backend, set_auth_token, UserInfo } from "../utils";
|
import { backend, UserInfo } from "../utils";
|
||||||
import { Card } from "../components/Card";
|
import { Card } from "../components/Card";
|
||||||
import { AxiosError } from "axios";
|
import { AxiosError } from "axios";
|
||||||
|
|
||||||
@ -119,7 +119,6 @@ function UserRegistration(props: {setUserInfo: (u: UserInfo) => void}) {
|
|||||||
props.setUserInfo(response.data);
|
props.setUserInfo(response.data);
|
||||||
localStorage.setItem(userIdKey, response.data.UserId);
|
localStorage.setItem(userIdKey, response.data.UserId);
|
||||||
localStorage.setItem(usernameKey, response.data.Username);
|
localStorage.setItem(usernameKey, response.data.Username);
|
||||||
set_auth_token(response.data.UserId);
|
|
||||||
} catch (_e) {
|
} catch (_e) {
|
||||||
const e = _e as AxiosError<{error: string}>;
|
const e = _e as AxiosError<{error: string}>;
|
||||||
|
|
||||||
@ -164,27 +163,14 @@ function UserRegistration(props: {setUserInfo: (u: UserInfo) => void}) {
|
|||||||
|
|
||||||
function LobbyConnection() {
|
function LobbyConnection() {
|
||||||
const [loading, setLoading] = createSignal(false);
|
const [loading, setLoading] = createSignal(false);
|
||||||
const [error, setError] = createSignal("");
|
|
||||||
const navigate = useNavigate();
|
|
||||||
|
|
||||||
const joinLobby = (ev: Event) => {
|
const joinLobby = (ev: Event) => {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
};
|
};
|
||||||
|
|
||||||
const createLobby = async() => {
|
const createLobby = async() => {
|
||||||
|
//
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
try {
|
|
||||||
const res = await backend.post<{LobbyId: string}>("/lobby/new");
|
|
||||||
console.log(res.data);
|
|
||||||
// Redirect to the lobby component using the received lobby id
|
|
||||||
navigate(`/lobby/${res.data.LobbyId}`);
|
|
||||||
} catch (_e) {
|
|
||||||
const e: Error = _e as Error;
|
|
||||||
setError(e.message);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -223,7 +209,6 @@ function LobbyConnection() {
|
|||||||
Create a new lobby
|
Create a new lobby
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<p>{error()}</p>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
14
src/utils.ts
14
src/utils.ts
@ -1,21 +1,9 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
export let backend = axios.create({
|
export const backend = axios.create({
|
||||||
baseURL: `${import.meta.env.VITE_BACKEND_URL}/api`,
|
baseURL: `${import.meta.env.VITE_BACKEND_URL}/api`,
|
||||||
headers: {
|
|
||||||
"Authorization": `Bearer ${localStorage.getItem("UserId") ?? ""}`,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export function set_auth_token(token: string) {
|
|
||||||
backend = axios.create({
|
|
||||||
baseURL: `${import.meta.env.VITE_BACKEND_URL}/api`,
|
|
||||||
headers: {
|
|
||||||
"Authorization": `Bearer ${token}`,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export type UserInfo = {
|
export type UserInfo = {
|
||||||
UserId: string,
|
UserId: string,
|
||||||
Username: string,
|
Username: string,
|
||||||
|
Loading…
Reference in New Issue
Block a user