diff --git a/src/api/client.ts b/src/api/client.ts index 7dc70a2..c9839b2 100644 --- a/src/api/client.ts +++ b/src/api/client.ts @@ -19,7 +19,7 @@ export async function apiFetch( }, }) - if (res.status === 401) { + if (res.status === 401 && auth.token) { await clearAuthData() router.push('/login') throw new Error("Session expired") diff --git a/src/api/rooms.ts b/src/api/rooms.ts index 29c8ac4..c26149d 100644 --- a/src/api/rooms.ts +++ b/src/api/rooms.ts @@ -5,6 +5,10 @@ export function fetchRooms() { return apiFetch(`/rooms`) } +export function fetchRoomInfo(uuid: string) { + return apiFetch(`/rooms/${uuid}`) +} + export function createRoom(name: string, global: boolean) { return apiFetch('/rooms', { method: 'POST', diff --git a/src/authStore.ts b/src/authStore.ts index bbc7f96..01be67d 100644 --- a/src/authStore.ts +++ b/src/authStore.ts @@ -1,4 +1,5 @@ import { load, Store } from '@tauri-apps/plugin-store' +import { User } from './types' let store: Store | null = null @@ -10,21 +11,22 @@ async function getStore() { export async function getAuthData() { const s = await getStore() const token = await s.get('token') - const uuid = await s.get('uuid') - return { token: token || null, uuid: uuid || null, isAuthenticated: !!token } + const user = await s.get('user') + return { token: token || null, user: user || null, isAuthenticated: !!token } } -export async function saveAuthData(token: string, uuid: string) { +export async function saveAuthData(token: string, user: User) { const s = await getStore() await s.set('token', token) - await s.set('uuid', uuid) + await s.set('user', user) await s.save() } export async function clearAuthData() { const s = await getStore() await s.delete('token') - await s.delete('uuid') + await s.delete('user') + await s.delete('last_room_uuid') await s.save() } diff --git a/src/components/ChatWindow.vue b/src/components/ChatWindow.vue index 8f3f2f7..496b4a4 100644 --- a/src/components/ChatWindow.vue +++ b/src/components/ChatWindow.vue @@ -1,4 +1,6 @@ + + diff --git a/src/components/RoomList.vue b/src/components/RoomList.vue index 49d85c4..95a0372 100644 --- a/src/components/RoomList.vue +++ b/src/components/RoomList.vue @@ -2,7 +2,8 @@

Rooms

- +
@@ -22,7 +23,6 @@ diff --git a/src/pages/ChatPage.vue b/src/pages/ChatPage.vue index c8a25ae..dd0bc4f 100644 --- a/src/pages/ChatPage.vue +++ b/src/pages/ChatPage.vue @@ -12,7 +12,7 @@ -
+
@@ -99,6 +99,12 @@ const handleRoomSelection = () => { font-size: 1.6rem; } +@media (min-width: 721px) { + .chat-window-container.sidebar-is-open { + padding-left: 0; + } +} + @media (max-width: 720px) { .sidebar { position: absolute; diff --git a/src/pages/NotificationsPage.vue b/src/pages/NotificationsPage.vue index e777097..60063c7 100644 --- a/src/pages/NotificationsPage.vue +++ b/src/pages/NotificationsPage.vue @@ -63,6 +63,7 @@ async function acceptRoom(senderUuid: string, roomUuid: string) { // fetchFriends().then(f => (friends.value = f)) } catch (err) { errorMessage.value = 'An error occurred while accepting the invite.' // TODO: handle this case + throw err } } diff --git a/src/store.ts b/src/store.ts index 18e0b9a..11afa33 100644 --- a/src/store.ts +++ b/src/store.ts @@ -1,5 +1,5 @@ import { apiFetch } from './api/client' -import type { LoginResponse } from './types' +import type { LoginResponse, User } from './types' import * as authStore from './authStore' export const initAuth = authStore.getAuthData @@ -12,7 +12,11 @@ export async function login(email: string, username: string, password: string) { body: JSON.stringify({ email, username, password }), }) - await authStore.saveAuthData(res.token, res.uuid) + let user: User = { + uuid: res.uuid, + username: username + }; + await authStore.saveAuthData(res.token, user) return { token: res.token, uuid: res.uuid, isAuthenticated: true } } diff --git a/src/types.ts b/src/types.ts index 6aab130..e7f0e39 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,3 +1,8 @@ +export interface User { + uuid: string + username: string +} + export interface LoginResponse { uuid: string token: string @@ -5,9 +10,10 @@ export interface LoginResponse { export interface Room { uuid: string - owner_name: number + owner_name: string + owner_uuid: string name: string - globa: boolean + global: boolean } export interface Message {