Issue
I need to implement a socket.io client in Angular and I found ngx-socket-io. It seems to work fine, but I didn't find an option to send credentials when starting the connection, as described on the official page, using auth > token. (https://socket.io/docs/v4/middlewares/#Sending-credentials)
I already have the server implemented and working in this format, getting the data from socket.handshake.auth.token.
How do I send this token through ngx-socket-io?
Are there any other socket.io libraries that I can use in angular?
Solution
I found a workaround, inserting empty options in the constructor and adding authentication right after. It's not ideal, but it seems to work normally. I'm sharing it here in case anyone else needs it.
import { AuthService } from '@my/core';
import { Socket } from 'ngx-socket-io';
import { environment } from 'src/environments/environment';
export class MySocket extends Socket {
constructor(
private authService: AuthService,
) {
super({ url: environment.urlSocket, options: {} });
this.ioSocket['auth'] = { token: this.authService.token };
}
}
Answered By - Edu Müller
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.