diff --git a/src/components/utilities/Notifications.vue b/src/components/utilities/Notifications.vue index c88de18..0fc1458 100644 --- a/src/components/utilities/Notifications.vue +++ b/src/components/utilities/Notifications.vue @@ -24,7 +24,6 @@ function closeNotification(id: string) { function setupNotificationListener(connection: any) { connection.on('notification', (data: { message: string }) => { notifications.addNotification({ - id: Math.random().toString(16), message: data.message }) }) diff --git a/src/services/authentication.ts b/src/services/authentication.ts index dfba9c1..83a9e69 100644 --- a/src/services/authentication.ts +++ b/src/services/authentication.ts @@ -15,14 +15,12 @@ export async function register(username: string, password: string, socketStore = } export async function login(username: string, password: string, socketStore = useSocketStore()) { - const response = await axios.post(`${config.server_endpoint}/login`, { username, password }) - - console.log(response.status, response.data); - if (response.status !== 200) { - return { error: response.data.message } + try { + const response = await axios.post(`${config.server_endpoint}/login`, { username, password }) + useCookies().set('token', response.data.token as string) + await socketStore.setupSocketConnection() + return { success: true } + } catch (error: any) { + return { error: error.response.data.message } } - - useCookies().set('token', response.data.token as string) - await socketStore.setupSocketConnection() - return { success: true } } diff --git a/src/stores/notifications.ts b/src/stores/notifications.ts index 58417dc..4f75e00 100644 --- a/src/stores/notifications.ts +++ b/src/stores/notifications.ts @@ -10,6 +10,9 @@ export const useNotificationStore: StoreDefinition = defineStore('notifications' }, actions: { addNotification(notification: Notification) { + if (!notification.id) { + notification.id = Math.random().toString(16) + } this.notifications.push(notification) }, removeNotification(id: string) {