added an authenticated room websocket for messages
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user