added an authenticated room websocket for messages

This commit is contained in:
2025-12-15 19:51:31 +01:00
parent 22c187e4ee
commit 4d939f611d
4 changed files with 85 additions and 15 deletions

View File

@@ -1,6 +1,5 @@
import { initAuth } from '../stores/auth.ts'
const BASE_URL = 'http://localhost:8080'
import { API } from '../main.ts'
export async function apiFetch<T>(
path: string,
@@ -8,7 +7,7 @@ export async function apiFetch<T>(
): Promise<T> {
const auth = await initAuth()
const res = await fetch(`${BASE_URL}${path}`, {
const res = await fetch(`${API}${path}`, {
...options,
headers: {
'Content-Type': 'application/json',

View File

@@ -15,3 +15,7 @@ export function sendMessage(roomUuid: string, content: string) {
})
}
export async function getWsToken(roomUuid: string): Promise<string> {
const data = await apiFetch<{ token: string }>(`/ws/issue-token/rooms/${roomUuid}`);
return data.token;
}