Skip to content

Commit e4cc13c

Browse files
committed
fix webscokets for chats
1 parent 19a7319 commit e4cc13c

4 files changed

Lines changed: 16 additions & 7 deletions

File tree

projects/core/src/lib/services/token.service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { map, Observable } from "rxjs";
55
import { RefreshResponse } from "@auth/models/http.model";
66
import { plainToInstance } from "class-transformer";
77
import { Tokens } from "@auth/models/tokens.model";
8-
import Cookies from "js-cookie";
8+
import Cookies, { CookieAttributes } from "js-cookie";
99
import { ApiService, PRODUCTION } from "@corelib";
1010

1111
/**
@@ -66,11 +66,13 @@ export class TokenService {
6666
* - Используются дефолтные настройки браузера
6767
* - Cookies привязаны к текущему домену
6868
*/
69-
getCookieOptions() {
69+
getCookieOptions(): CookieAttributes {
7070
if (this.production) {
7171
return {
7272
domain: ".procollab.ru", // Домен для production окружения
7373
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 30), // 30 дней
74+
secure: true,
75+
sameSite: "None",
7476
};
7577
}
7678

projects/social_platform/src/app/core/services/websocket.service.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/** @format */
2-
import { Injectable } from "@angular/core";
2+
import { inject, Injectable } from "@angular/core";
33
import { filter, map, Observable, Observer, retry, Subject } from "rxjs";
44
import { environment } from "@environment";
55
import * as snakecaseKeys from "snakecase-keys";
66
import camelcaseKeys from "camelcase-keys";
7+
import { TokenService } from "@corelib";
78

89
/**
910
* Сервис для работы с WebSocket соединениями
@@ -20,6 +21,8 @@ export class WebsocketService {
2021
/** Subject для обработки входящих сообщений */
2122
private messages$ = new Subject<MessageEvent>();
2223

24+
private readonly tokenService = inject(TokenService);
25+
2326
/** Флаг состояния соединения */
2427
public isConnected = false;
2528

@@ -36,7 +39,11 @@ export class WebsocketService {
3639
*/
3740
public connect(path: string): Observable<void> {
3841
return new Observable((observer: Observer<void>) => {
39-
this.socket = new WebSocket(environment.websocketUrl + path);
42+
const tokens = this.tokenService.getTokens();
43+
44+
const tokenAccess = tokens?.access ? tokens.access : "";
45+
46+
this.socket = new WebSocket(environment.websocketUrl + path, ["Bearer", tokenAccess]);
4047

4148
this.socket.onopen = () => {
4249
this.isConnected = true;

projects/social_platform/src/app/office/services/chat.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class ChatService {
5757
const tokens = this.tokenService.getTokens();
5858
if (!tokens) throw new Error("No token provided");
5959

60-
return this.websocketService.connect(`/chat/?token=${tokens.access}`);
60+
return this.websocketService.connect(`/chat/`);
6161
}
6262

6363
/**

projects/social_platform/src/app/ui/components/input/input.component.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@
112112
display: flex;
113113
align-items: center;
114114
justify-content: center;
115+
padding: 0 4px;
115116
color: var(--red) !important;
116-
transform: translateY(-50%);
117117
background: var(--ligth-white);
118-
padding: 0 4px;
118+
transform: translateY(-50%);
119119
}
120120

121121
&__right-icon {

0 commit comments

Comments
 (0)