AAE-30358 Remove client if already exists when connection is closed to use the refreshed token changing the page, turn connectionParams into a function to ensures that the latest token is always used for WebSocket connections

This commit is contained in:
alep85 2025-04-14 14:46:27 +02:00
parent d09b8daa3a
commit 76999ee830
No known key found for this signature in database
GPG Key ID: AB4BE8E091FD24C8
2 changed files with 12 additions and 3 deletions

View File

@ -27,7 +27,7 @@ describe('WebSocketService', () => {
let service: WebSocketService;
const onLogoutSubject: Subject<void> = new Subject<void>();
const apolloMock = jasmine.createSpyObj('Apollo', ['use', 'createNamed']);
const apolloMock = jasmine.createSpyObj('Apollo', ['use', 'createNamed', 'removeClient']);
beforeEach(() => {
TestBed.configureTestingModule({

View File

@ -72,6 +72,12 @@ export class WebSocketService {
return this.apollo.use(apolloClientName).subscribe<T>({ errorPolicy: 'all', ...subscriptionOptions });
}
private removeApolloClientIfExists(apolloClientName: string) {
if (this.apollo.use(apolloClientName)) {
this.apollo.removeClient(apolloClientName);
}
}
private get contextRoot() {
return this.appConfigService.get('bpmHost', '');
}
@ -155,10 +161,13 @@ export class WebSocketService {
this.wsLink = new GraphQLWsLink(
createClient({
url: this.createWsUrl(options.wsUrl) + '/v2/ws/graphql',
connectionParams: {
connectionParams: () => ({
Authorization: 'Bearer ' + this.authService.getToken()
},
}),
on: {
closed: () => {
this.removeApolloClientIfExists(options.apolloClientName);
},
error: () => {
this.apollo.removeClient(options.apolloClientName);
this.initSubscriptions(options);