-
Notifications
You must be signed in to change notification settings - Fork 683
How do we use DI with separate client/server services? #148
Comments
^ You can see a small example of it there that Patrick did a while back. |
Thanks, this was a helpful example. What I gather from it is that the pattern works in the following way:
Is my understanding correct regarding this pattern? |
Yes, basically you're giving a "dummy" class, that either client or server then override with their own (in provide) implementation. You just need a base structured class that each correspond with. We have plenty of documentation we need to add, for now changes keep coming so quickly it's hard to keep up. But it's definitely on the to do list! |
I was able to do it with an interface:
Then in the router config I just used the AUTH_GUARD. If you are injecting it in a constructor then you can use And at injection time (main.browser.ts): and main.node.ts: Also, to pass parameters to any one of the two classes, just injecting them in one (or both) constructor(s) works, if we add them to the providers array in the respective main.*.ts file(s). In my case I was able to pass the Express request to the ServerAuthGuard like this:
where CLIENT_REQUEST is another OpaqueToken. |
Ah you're using it to prevent a Component from initializing if it's not authorized? Very nice! |
I want to integrate authentication in a Angular Universal app. I found this example: https://gist.github.com/jhades/4d9e1422b020b10acaf616d3ee4a3db7 which shows how to do it with a common Client / Server interface and a Server service no-op implementation. But it's not clear how to actually use these services in the Universal app.
I found this pattern referenced in a few places regarding Angular Universal but no example of a setup that does this. I think it will be very helpful to integrate a mock service with different client/server implementation into the universal-starter project.
The text was updated successfully, but these errors were encountered: