ngrx - Prevent Effects from bootstrapping before user login
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I'm having an issue with NgRx Effects bootstrapping before the user logs in, which is causing my services to be instantiated with wrong headers (cause after log in, I set a couple cookies and use them to set the headers, as those services are initialised before log in, they don't have the headers).
I have a huge application and only a couple of features are using NgRx.
When the user logs in, it gets routed and another module is initialised. The legacy features (and it's modules) inside this workspace module then are initialised and every service is instantiated correctly (cause I have the data I need already set to use for the headers).
But my NgRx features, also inside this workspace module, are initialised on app start, not on module route.
This happens due to NgRx going over my Effects, which have the services injected. So the services I have inside my Effects are instantiated before login.
I went over a couple GitHub issues and articles and this is a known discussion, but the needs approached by the people that wrote those issues and articles are different than mine and I wasn't able to figure out by myself how to take the answers and do something for my problem.
The articles are about APP_INITIALIZER and Effects bootstrap not respecting it (#931, #174, NgRx docs, Hackernoon and itnext)
How can I work with that to make my Effects wait for something?
(Ps: Is there a NgRx life cycle docs for me to understand what's going on under the hood?)
Thanks.
add a comment |
I'm having an issue with NgRx Effects bootstrapping before the user logs in, which is causing my services to be instantiated with wrong headers (cause after log in, I set a couple cookies and use them to set the headers, as those services are initialised before log in, they don't have the headers).
I have a huge application and only a couple of features are using NgRx.
When the user logs in, it gets routed and another module is initialised. The legacy features (and it's modules) inside this workspace module then are initialised and every service is instantiated correctly (cause I have the data I need already set to use for the headers).
But my NgRx features, also inside this workspace module, are initialised on app start, not on module route.
This happens due to NgRx going over my Effects, which have the services injected. So the services I have inside my Effects are instantiated before login.
I went over a couple GitHub issues and articles and this is a known discussion, but the needs approached by the people that wrote those issues and articles are different than mine and I wasn't able to figure out by myself how to take the answers and do something for my problem.
The articles are about APP_INITIALIZER and Effects bootstrap not respecting it (#931, #174, NgRx docs, Hackernoon and itnext)
How can I work with that to make my Effects wait for something?
(Ps: Is there a NgRx life cycle docs for me to understand what's going on under the hood?)
Thanks.
1
Why doesn't the hookOnRunEffectswork for you?
– timdeschryver
Jan 4 at 17:34
Hi and thanks for the reply. I'm afraid I'm not sure I understood how this works reading by the docs (github.com/ngrx/platform/blob/master/docs/effects/…) and wanted or a reference to, as I asked for, the life cycle or to people to discuss with me. I'll right now try to read more about that and maybe it will fit me, but I still would like to understand the big picture of that. Real thanks.
– João Ghignatti
Jan 4 at 17:53
1
It will only execute the effects after the LOGIN action. Once there is a LOGOUT action, it won't execute anymore.
– timdeschryver
Jan 4 at 18:41
And it would create a giant boilerplate as I keep rewriting the legacy features into ngrx, right? Any work around that?
– João Ghignatti
Jan 4 at 18:43
1
I think you should be able to create a custom RxJS operator, to prevent writing the same code.
– timdeschryver
Jan 4 at 18:59
add a comment |
I'm having an issue with NgRx Effects bootstrapping before the user logs in, which is causing my services to be instantiated with wrong headers (cause after log in, I set a couple cookies and use them to set the headers, as those services are initialised before log in, they don't have the headers).
I have a huge application and only a couple of features are using NgRx.
When the user logs in, it gets routed and another module is initialised. The legacy features (and it's modules) inside this workspace module then are initialised and every service is instantiated correctly (cause I have the data I need already set to use for the headers).
But my NgRx features, also inside this workspace module, are initialised on app start, not on module route.
This happens due to NgRx going over my Effects, which have the services injected. So the services I have inside my Effects are instantiated before login.
I went over a couple GitHub issues and articles and this is a known discussion, but the needs approached by the people that wrote those issues and articles are different than mine and I wasn't able to figure out by myself how to take the answers and do something for my problem.
The articles are about APP_INITIALIZER and Effects bootstrap not respecting it (#931, #174, NgRx docs, Hackernoon and itnext)
How can I work with that to make my Effects wait for something?
(Ps: Is there a NgRx life cycle docs for me to understand what's going on under the hood?)
Thanks.
I'm having an issue with NgRx Effects bootstrapping before the user logs in, which is causing my services to be instantiated with wrong headers (cause after log in, I set a couple cookies and use them to set the headers, as those services are initialised before log in, they don't have the headers).
I have a huge application and only a couple of features are using NgRx.
When the user logs in, it gets routed and another module is initialised. The legacy features (and it's modules) inside this workspace module then are initialised and every service is instantiated correctly (cause I have the data I need already set to use for the headers).
But my NgRx features, also inside this workspace module, are initialised on app start, not on module route.
This happens due to NgRx going over my Effects, which have the services injected. So the services I have inside my Effects are instantiated before login.
I went over a couple GitHub issues and articles and this is a known discussion, but the needs approached by the people that wrote those issues and articles are different than mine and I wasn't able to figure out by myself how to take the answers and do something for my problem.
The articles are about APP_INITIALIZER and Effects bootstrap not respecting it (#931, #174, NgRx docs, Hackernoon and itnext)
How can I work with that to make my Effects wait for something?
(Ps: Is there a NgRx life cycle docs for me to understand what's going on under the hood?)
Thanks.
edited Jan 4 at 17:45
Ivan Kaloyanov
1,24431019
1,24431019
asked Jan 4 at 17:09
João GhignattiJoão Ghignatti
374314
374314
1
Why doesn't the hookOnRunEffectswork for you?
– timdeschryver
Jan 4 at 17:34
Hi and thanks for the reply. I'm afraid I'm not sure I understood how this works reading by the docs (github.com/ngrx/platform/blob/master/docs/effects/…) and wanted or a reference to, as I asked for, the life cycle or to people to discuss with me. I'll right now try to read more about that and maybe it will fit me, but I still would like to understand the big picture of that. Real thanks.
– João Ghignatti
Jan 4 at 17:53
1
It will only execute the effects after the LOGIN action. Once there is a LOGOUT action, it won't execute anymore.
– timdeschryver
Jan 4 at 18:41
And it would create a giant boilerplate as I keep rewriting the legacy features into ngrx, right? Any work around that?
– João Ghignatti
Jan 4 at 18:43
1
I think you should be able to create a custom RxJS operator, to prevent writing the same code.
– timdeschryver
Jan 4 at 18:59
add a comment |
1
Why doesn't the hookOnRunEffectswork for you?
– timdeschryver
Jan 4 at 17:34
Hi and thanks for the reply. I'm afraid I'm not sure I understood how this works reading by the docs (github.com/ngrx/platform/blob/master/docs/effects/…) and wanted or a reference to, as I asked for, the life cycle or to people to discuss with me. I'll right now try to read more about that and maybe it will fit me, but I still would like to understand the big picture of that. Real thanks.
– João Ghignatti
Jan 4 at 17:53
1
It will only execute the effects after the LOGIN action. Once there is a LOGOUT action, it won't execute anymore.
– timdeschryver
Jan 4 at 18:41
And it would create a giant boilerplate as I keep rewriting the legacy features into ngrx, right? Any work around that?
– João Ghignatti
Jan 4 at 18:43
1
I think you should be able to create a custom RxJS operator, to prevent writing the same code.
– timdeschryver
Jan 4 at 18:59
1
1
Why doesn't the hook
OnRunEffects work for you?– timdeschryver
Jan 4 at 17:34
Why doesn't the hook
OnRunEffects work for you?– timdeschryver
Jan 4 at 17:34
Hi and thanks for the reply. I'm afraid I'm not sure I understood how this works reading by the docs (github.com/ngrx/platform/blob/master/docs/effects/…) and wanted or a reference to, as I asked for, the life cycle or to people to discuss with me. I'll right now try to read more about that and maybe it will fit me, but I still would like to understand the big picture of that. Real thanks.
– João Ghignatti
Jan 4 at 17:53
Hi and thanks for the reply. I'm afraid I'm not sure I understood how this works reading by the docs (github.com/ngrx/platform/blob/master/docs/effects/…) and wanted or a reference to, as I asked for, the life cycle or to people to discuss with me. I'll right now try to read more about that and maybe it will fit me, but I still would like to understand the big picture of that. Real thanks.
– João Ghignatti
Jan 4 at 17:53
1
1
It will only execute the effects after the LOGIN action. Once there is a LOGOUT action, it won't execute anymore.
– timdeschryver
Jan 4 at 18:41
It will only execute the effects after the LOGIN action. Once there is a LOGOUT action, it won't execute anymore.
– timdeschryver
Jan 4 at 18:41
And it would create a giant boilerplate as I keep rewriting the legacy features into ngrx, right? Any work around that?
– João Ghignatti
Jan 4 at 18:43
And it would create a giant boilerplate as I keep rewriting the legacy features into ngrx, right? Any work around that?
– João Ghignatti
Jan 4 at 18:43
1
1
I think you should be able to create a custom RxJS operator, to prevent writing the same code.
– timdeschryver
Jan 4 at 18:59
I think you should be able to create a custom RxJS operator, to prevent writing the same code.
– timdeschryver
Jan 4 at 18:59
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54043286%2fngrx-prevent-effects-from-bootstrapping-before-user-login%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54043286%2fngrx-prevent-effects-from-bootstrapping-before-user-login%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Why doesn't the hook
OnRunEffectswork for you?– timdeschryver
Jan 4 at 17:34
Hi and thanks for the reply. I'm afraid I'm not sure I understood how this works reading by the docs (github.com/ngrx/platform/blob/master/docs/effects/…) and wanted or a reference to, as I asked for, the life cycle or to people to discuss with me. I'll right now try to read more about that and maybe it will fit me, but I still would like to understand the big picture of that. Real thanks.
– João Ghignatti
Jan 4 at 17:53
1
It will only execute the effects after the LOGIN action. Once there is a LOGOUT action, it won't execute anymore.
– timdeschryver
Jan 4 at 18:41
And it would create a giant boilerplate as I keep rewriting the legacy features into ngrx, right? Any work around that?
– João Ghignatti
Jan 4 at 18:43
1
I think you should be able to create a custom RxJS operator, to prevent writing the same code.
– timdeschryver
Jan 4 at 18:59