added timestamps to messages
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { initAuth } from '../stores/auth.ts'
|
import { initAuth } from '../stores/auth.ts'
|
||||||
|
|
||||||
const BASE_URL = 'http://192.168.1.183:8081'
|
const BASE_URL = 'http://localhost:8080'
|
||||||
|
|
||||||
export async function apiFetch<T>(
|
export async function apiFetch<T>(
|
||||||
path: string,
|
path: string,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ defineProps<{ messages: Message[] }>()
|
|||||||
<template>
|
<template>
|
||||||
<ul>
|
<ul>
|
||||||
<li v-for="(m, i) in messages" :key="i" class="message">
|
<li v-for="(m, i) in messages" :key="i" class="message">
|
||||||
<div class="sender">{{ m.sender }}</div>
|
<div class="sender">{{ m.sender }} <span class="timestamp">{{ m.sent_at }}</span></div>
|
||||||
<div class="message-content">{{ m.content }}</div>
|
<div class="message-content">{{ m.content }}</div>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -20,14 +20,25 @@ ul {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.message {
|
.message {
|
||||||
margin-bottom: 1rem;
|
margin-bottom: 0.5rem;
|
||||||
|
background-color: rgba(0, 0, 0, 0.2);
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: var(--radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
.sender {
|
.sender {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
|
font-size: 1.1rem;
|
||||||
margin-bottom: 0.25rem;
|
margin-bottom: 0.25rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sender .timestamp {
|
||||||
|
font-weight: normal;
|
||||||
|
opacity: 0.7;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
margin-left: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
.message-content {
|
.message-content {
|
||||||
padding-left: 1rem;
|
padding-left: 1rem;
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { createRouter, createWebHistory } from 'vue-router'
|
import { createRouter, createWebHistory } from 'vue-router'
|
||||||
import { initAuth } from '../stores/auth.ts'
|
import { initAuth, validateToken } from '../stores/auth.ts'
|
||||||
|
|
||||||
import LoginPage from '../pages/LoginPage.vue'
|
import LoginPage from '../pages/LoginPage.vue'
|
||||||
import RoomsPage from '../pages/RoomsPage.vue'
|
import RoomsPage from '../pages/RoomsPage.vue'
|
||||||
@@ -16,9 +16,15 @@ const router = createRouter({
|
|||||||
|
|
||||||
router.beforeEach(async (to) => {
|
router.beforeEach(async (to) => {
|
||||||
const auth = await initAuth()
|
const auth = await initAuth()
|
||||||
|
|
||||||
if (!auth.isAuthenticated && to.path !== '/login') {
|
if (!auth.isAuthenticated && to.path !== '/login') {
|
||||||
return '/login'
|
return '/login'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (auth.isAuthenticated) {
|
||||||
|
const valid = await validateToken()
|
||||||
|
if (!valid) return '/login'
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
export default router
|
export default router
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ let store: Store | null = null
|
|||||||
|
|
||||||
async function getStore() {
|
async function getStore() {
|
||||||
if (!store) {
|
if (!store) {
|
||||||
store = await load('store.json', { autoSave: false })
|
store = await load('store.json')
|
||||||
}
|
}
|
||||||
return store
|
return store
|
||||||
}
|
}
|
||||||
@@ -39,3 +39,21 @@ export async function logout() {
|
|||||||
await s.save()
|
await s.save()
|
||||||
return { token: null, uuid: null, isAuthenticated: false }
|
return { token: null, uuid: null, isAuthenticated: false }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function validateToken(): Promise<boolean> {
|
||||||
|
const auth = await initAuth()
|
||||||
|
if (!auth.token) return false
|
||||||
|
|
||||||
|
try {
|
||||||
|
await apiFetch('/validate-token', {
|
||||||
|
method: 'GET',
|
||||||
|
})
|
||||||
|
return true
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
|
||||||
|
await logout()
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,5 +13,6 @@ export interface Message {
|
|||||||
sender: string
|
sender: string
|
||||||
message_type: 'text'
|
message_type: 'text'
|
||||||
content: string
|
content: string
|
||||||
|
sent_at: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user