-
Notifications
You must be signed in to change notification settings - Fork 2k
Fix redirection to previous state after required authentication #901
Conversation
@igorauad did we not have tests for this? |
Not yet, @ilanbiala . I don't think so. |
@igorauad can you also add tests to this PR then? Depending on how quickly we can get this rolling (hopefully for 0.4.2), then I'll milestone it right before we merge. |
Sure, @ilanbiala . Just give me some time. I will probably find time tomorrow. |
@igorauad great find, but the proposed solution needs some work. We should avoid firing the success event, when the state was not successful (it was interrupted). There is a better way to preserve the previous (interrupted state) without an event trigger. The reason I am against reusing the event is because your assumption is that it will only trigger the listener to record the previous state - you are not considering that there may be other listeners. |
@igorauad I agree with @rhutchison that we don't want to fire the $stateChangeSuccess again. This would end up firing it twice in that cycle. Among the other reasons that Ryan mentioned. I pulled down your branch locally, and made modifications as an alternative to this solution. Let me know if you think this will suffice? |
@@ -30,7 +30,9 @@ angular.module(ApplicationConfiguration.applicationModuleName).run(function ($ro | |||
if (Authentication.user !== undefined && typeof Authentication.user === 'object') { | |||
$state.go('forbidden'); | |||
} else { | |||
$state.go('authentication.signin'); | |||
$state.go('authentication.signin').then(function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also use something like $state.go('authentication.signin', {warn: 'Please, sign in first.'})
here. Then, print that in alert in the signin
template. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@igorauad What would that accomplish?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mleanos just UX, for me it seems better to let the user know why the signin page is being displayed rather than the requested one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think most users know nowadays, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes @ilanbiala Ok, in fact that depends on the audience and the application, so we shouldn't worry about it here.
LGTM |
@igorauad any tests you can throw in? |
Yes @ilanbiala , I just need to learn a bit about tests, because I'm not experienced on this yet :) These tests should be included in If anybody want to contribute first, feel free. |
@igorauad yeah probably, seems most appropriate there. Add whatever you can and we'll go from there. |
@ilanbiala just pushed my first attempt. Not yet successful :( any hints? |
@igorauad Do the tests pass locally for you? |
@mleanos nop, I'm on the learning curve yet. Just pushed following the advice from @ilanbiala: "Add whatever you can and we'll go from there." |
@igorauad Ok, that's fine. I'll try on my end.. I'm not proficient with the Karma tests yet either. Maybe together we'll both learn from this :) |
Cool @mleanos :) |
Error for reference:
@igorauad I think either the spy isn't on the right thing or scope.signin isn't calling, but I'll look into it more tomorrow when I have time. |
|
||
scope.signin(true); | ||
$httpBackend.flush(); | ||
spyOn($state, 'transitionTo'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be set before scope.signin(true)
(line 77).
However, even after that modification, the test doesn't pass. The actuals returned from the below expect
don't match up with the previous state defined in this test. Upon further investigation, I logged $state.previous
to the console in the signin method of the AuthenticationController & it was equal to the previous state defined here in this test. Lastly, I logged a test to the console from ChatController & it didn't log. So it appears, it's never getting to the previous state. Somewhat of a head scratcher.
Anyone else wanna take a shot at this? I'll keep working on it, but probably could use a fresh set of eyes.
@ilanbiala @igorauad I was able to get the test to pass.. It appears that both the
|
@igorauad can you see if that solves it for you and if so push it? |
@ilanbiala just pushed. Yes, it solves. If somebody understand exactly why, that would be interesting to know. Thank you very much @mleanos |
@igorauad Looks like timeout errors, during the build. Hopefully, it was due to a hiccup with Mongo. @ilanbiala @lirantal Do you have the ability to re-run the CI builds for this PR? |
@igorauad It's nice that at least the coveralls increased :) |
|
Yes, I re-ran the build now, let's see how it goes. |
CI LGTM now. |
Is there anything else we should do on this? |
@igorauad Squash, and it should be good. |
LGTM. Just needs squashing. |
Fixes the issue with the previous state not being recorded, when the unauthenticated user is redirected to the signin state, when trying to access a restricted route. Added a function that stores the provided state & state params, in the $state.previous object. This has been implemented in the $stateChangeSuccess event, and the callback of the $state.go transition when the user is not allowed to access the requested route.
a9cd4ce
to
2b8bee0
Compare
@igorauad Thanks |
Thanks, @mleanos |
Fix redirection to previous state after required authentication
$stateChangeSuccess
event should be signaled in order to allow "recording" of previous state.This part of the implementation was missing, I just realized that.