diff --git a/frontend-service/src/main/vue/controllers/notifications/notification-service.ts b/frontend-service/src/main/vue/controllers/notifications/notification-service.ts index d4e048b8f..f3ccac96e 100644 --- a/frontend-service/src/main/vue/controllers/notifications/notification-service.ts +++ b/frontend-service/src/main/vue/controllers/notifications/notification-service.ts @@ -20,6 +20,7 @@ import { useAppStore } from "@/stores/app"; import { useFriendStore } from "@/stores/friend"; import { useNotificationStore } from "@/stores/notifications"; import { useUsersStatusStore } from "@/stores/status"; +import { AxiosController } from "@/controllers/axios-controller"; class NotificationService { callbacks: Record Promise> = {}; @@ -222,10 +223,20 @@ function createNotificationService() { } export function useNotificationService() { + const userStorage = localStorage.getItem("user"); + const user = userStorage ? JSON.parse(userStorage) : null; + const accessToken = user ? user.jwt : null; + + if (!accessToken) { + throw new Error("User not logged in"); + } const notificationService = createNotificationService(); const notificationSocket = io({ transports: ["websocket"], path: "/notification", + extraHeaders: { + Authorization: `Bearer ${accessToken}`, + }, }); notificationSocket.on("connect", () => { diff --git a/notifications-service/src/main/typescript/notification-service.ts b/notifications-service/src/main/typescript/notification-service.ts index 159885608..f452393fc 100644 --- a/notifications-service/src/main/typescript/notification-service.ts +++ b/notifications-service/src/main/typescript/notification-service.ts @@ -25,9 +25,10 @@ export class NotificationSocketServer { path: "/notification", }); this.io.on("connection", async (socket) => { - const jwt = this.getTokenFromHeadersCookie( - socket.handshake.headers.cookie - ); + // const jwt = this.getTokenFromHeadersCookie( + let jwt = socket.handshake.headers.authorization; + console.log(jwt); + // ); await this.validateTokenOrDisconnect(socket, jwt); const username = decodeAccessToken(jwt!)?.username; if (username) {