question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SocketIoModule.forRoot with factory ?

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:8

github_iconTop GitHub Comments

2reactions
dsebastiencommented, Jul 4, 2020

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).

0reactions
mtenorio-cmpcommented, Feb 12, 2021

@dsebastien Tienen algún ejemplo en github? mi problema es cuando recargan la pagina (F5)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found