Notifications bug fix
This commit is contained in:
parent
01bbd94a3e
commit
356cb94cc2
@ -24,7 +24,6 @@ function closeNotification(id: string) {
|
|||||||
function setupNotificationListener(connection: any) {
|
function setupNotificationListener(connection: any) {
|
||||||
connection.on('notification', (data: { message: string }) => {
|
connection.on('notification', (data: { message: string }) => {
|
||||||
notifications.addNotification({
|
notifications.addNotification({
|
||||||
id: Math.random().toString(16),
|
|
||||||
message: data.message
|
message: data.message
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -15,14 +15,12 @@ export async function register(username: string, password: string, socketStore =
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function login(username: string, password: string, socketStore = useSocketStore()) {
|
export async function login(username: string, password: string, socketStore = useSocketStore()) {
|
||||||
|
try {
|
||||||
const response = await axios.post(`${config.server_endpoint}/login`, { username, password })
|
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 }
|
|
||||||
}
|
|
||||||
|
|
||||||
useCookies().set('token', response.data.token as string)
|
useCookies().set('token', response.data.token as string)
|
||||||
await socketStore.setupSocketConnection()
|
await socketStore.setupSocketConnection()
|
||||||
return { success: true }
|
return { success: true }
|
||||||
|
} catch (error: any) {
|
||||||
|
return { error: error.response.data.message }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,9 @@ export const useNotificationStore: StoreDefinition = defineStore('notifications'
|
|||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
addNotification(notification: Notification) {
|
addNotification(notification: Notification) {
|
||||||
|
if (!notification.id) {
|
||||||
|
notification.id = Math.random().toString(16)
|
||||||
|
}
|
||||||
this.notifications.push(notification)
|
this.notifications.push(notification)
|
||||||
},
|
},
|
||||||
removeNotification(id: string) {
|
removeNotification(id: string) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user