Compare commits

..

No commits in common. "3b30f11d0f88f4d1bb815e5ff3f7210c6c02b6c0" and "b0b14bc5594ebd3c3e38fca368ef0161c2dddd8f" have entirely different histories.

2 changed files with 4 additions and 31 deletions

View File

@ -1,6 +1,6 @@
import { A, useNavigate } from "@solidjs/router";
import { A } from "@solidjs/router";
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 { AxiosError } from "axios";
@ -119,7 +119,6 @@ function UserRegistration(props: {setUserInfo: (u: UserInfo) => void}) {
props.setUserInfo(response.data);
localStorage.setItem(userIdKey, response.data.UserId);
localStorage.setItem(usernameKey, response.data.Username);
set_auth_token(response.data.UserId);
} catch (_e) {
const e = _e as AxiosError<{error: string}>;
@ -164,27 +163,14 @@ function UserRegistration(props: {setUserInfo: (u: UserInfo) => void}) {
function LobbyConnection() {
const [loading, setLoading] = createSignal(false);
const [error, setError] = createSignal("");
const navigate = useNavigate();
const joinLobby = (ev: Event) => {
ev.preventDefault();
};
const createLobby = async() => {
//
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 (
@ -223,7 +209,6 @@ function LobbyConnection() {
Create a new lobby
</button>
<p>{error()}</p>
</div>
);
}

View File

@ -1,21 +1,9 @@
import axios from "axios";
export let backend = axios.create({
export const backend = axios.create({
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 = {
UserId: string,
Username: string,