SocketIoModule.forRoot with factory ?
See original GitHub issueHi 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
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:8
Top Results From Across the Web
How to use the ngx-socket-io.SocketIoModule.forRoot function ...
To help you get started, we've selected a few ngx-socket-io.SocketIoModule.forRoot examples, based on popular ways it is used in public projects.
Read more >Angular 8 : ngx-socket-io rewrites connection url when ...
Solved it by using the service version instead of registering SocketIoModule in AppModule as per documentation in npm.
Read more >dist/src/socket-io.module.d.ts - jsDelivr
socketIoConfig'; /** Socket factory */ export declare function ... export declare class SocketIoModule { static forRoot(config: SocketIoConfig): ...
Read more >Providing Module Configuration Using forRoot() And Ahead ...
forRoot () "options" object as a proper dependency of our extracted factory function: // Import the core angular services. import ...
Read more >Getting Started with Ionic 4 and Socket.io - Devdactic
app-routing.module'; import { SocketIoModule, SocketIoConfig } from ... forRoot(config) ], providers: [ StatusBar, SplashScreen, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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).
@dsebastien Tienen algún ejemplo en github? mi problema es cuando recargan la pagina (F5)