ngx-socket-io
ngx-socket-io copied to clipboard
SocketIoModule.forRoot with factory ?
Hi there i'm using this module like this:
const config: SocketIoConfig = { url: endpoint.socket, options: {
query: {
token: localStorage.getItem('access_token')
}
}};
...
SocketIoModule.forRoot(config),
But i need to use Ionic storage instead of localstorage.
I'm wondering if there is a factory method to use like @auth0/angular-jwt:
export function jwtOptionsFactory(storage: Storage) {
return {
tokenGetter: () => {
return storage.get('access_token');
},
whitelistedDomains: endpoint.jwtWhitelist
}
....
JwtModule.forRoot({
jwtOptionsProvider: {
provide: JWT_OPTIONS,
useFactory: jwtOptionsFactory,
deps: [Storage]
}
}),
}
Regards
No factory to use ?
same issue
I'm also interested in having this. In addition, the capability to define whitelisted domains/origins is useful for security checks
Could you give some more information? I suppose this is to asynchronously retrieve things? Or is it for dependency injection into the factory arguments? Or both? :) If it's for async wouldn't you want to use Observables/async instead of a factory pattern?
Could you give some more information? I suppose this is to asynchronously retrieve things? Or is it for dependency injection into the factory arguments? Or both? :) If it's for async wouldn't you want to use Observables/async instead of a factory pattern?
For my purpose, it's for dependency injection (ionic storage).
Actually i've worked around this by following advice in another ticket. I don't use the .forRoot anymore, but a service with a "connect" method that I only invoke when the user is logged into my application.
That way, I can also provide the configuration lazily and thus I don't have this issue anymore.
The thing is that in most systems that require authentication, the WebSocket connection should only be established while the user is authenticated, so I suppose it would be nice to have support for this scenario (but indeed it's a separate feature request).
Na verdade, resolvi isso seguindo o conselho de outro tíquete. Eu não uso mais o .forRoot, mas um serviço com um método de "conexão" que só invoco quando o usuário está logado em meu aplicativo.
Dessa forma, também posso fornecer a configuração preguiçosamente e, portanto, não tenho mais esse problema.
O fato é que na maioria dos sistemas que requerem autenticação, a conexão WebSocket só deve ser estabelecida enquanto o usuário está autenticado, então suponho que seria bom ter suporte para este cenário (mas na verdade é uma solicitação de recurso separada).
Actually i've worked around this by following advice in another ticket. I don't use the .forRoot anymore, but a service with a "connect" method that I only invoke when the user is logged into my application.
That way, I can also provide the configuration lazily and thus I don't have this issue anymore.
The thing is that in most systems that require authentication, the WebSocket connection should only be established while the user is authenticated, so I suppose it would be nice to have support for this scenario (but indeed it's a separate feature request).
I have this same problem, I need to start my websocket only after the user is logged in, but when I try to create a service and inject in AppModule it is giving the same error as this issue #76, you could not post your solution in a fiddler or in a repository ?
@dsebastien Tienen algún ejemplo en github? mi problema es cuando recargan la pagina (F5)