Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Unauthorized client side routing #796

Merged
merged 1 commit into from
Aug 25, 2015

Conversation

trainerbill
Copy link
Contributor

Reintroducing to master branch. closing #727

@ilanbiala @lirantal @rhutchison @codydaig

@trainerbill trainerbill mentioned this pull request Aug 13, 2015
@lirantal lirantal added this to the 0.4.x milestone Aug 13, 2015
templateUrl: 'modules/core/views/400.client.view.html'
})
.state('unauthorized', {
url: '/unauthorized',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation

@trainerbill
Copy link
Contributor Author

@ilanbiala Not that I am looking at this, I don't think we should do interceptors for bad request on the client side.... Server side is throwing them quite a bit, even for things like article is not found. Guessing we don't want a redirect on these errors... Or do we?

@lirantal
Copy link
Member

@trainerbill can you elaborate more on the requirement/purpose of this PR? I'm not really following what's it about.

@rhutchison
Copy link
Contributor

Server side is throwing them quite a bit, even for things like article is not found. Guessing we don't want a redirect on these errors... Or do we?

@trainerbill yes, this is the intention. 404 should go use $state.transitionTo on the client to go to the 404 page. This will all make better sense when resolves are used properly.

I am not a fan of having the pub/sub implementation here, I don't see the value of doing it this way. The only thing I can think of is you tried implementing state.go in the http interceptor and ran in to the circular reference issue. You need to use $injector like so, $injector.get('$state').transitionTo('bad-request');

@trainerbill
Copy link
Contributor Author

@lirantal HTTP interceptors will do certain actions if the server responds with certain error codes. So for like an unauthorized 401 response I created a route so that the client will redirect to the route so the user knows they are unauthorized. This will come in handy when a user views an article then adds /edit to the end of the URL of an article that they don't own. I suggest pulling the branch and checking it out. Login with a user account and try to go to /admin/users. View an article the user doesn't own and add a /edit to the URL and try and edit the article. You will go to the unauthorized route.

@rhutchison The example you gave me was based on pub/sub. I actually like the idea. So then in the module controllers we can broadcast the unauth event and it does the same thing every time for certain events. $state couldn't be injected into config so that is why I went with pub/sub but after doing it I kinda like it. As a framework/middleware we should really have events like this to make it easier on the modules. Just do a $rootScope.broadcast(events) and we handle everything for the modules.

As for 404, the only reason I don't like it is because the backend throws them a lot. I don't think that redirecting to a bad-request route is a better option then just displaying the error on the client since the bad request error message is variable. Then the user has to hit the back button to get back to their previous state.

@trainerbill
Copy link
Contributor Author

@rhutchison Removed Modal, Removed Pub/Sub, changed unauthorized to forbidded to align with the http status code. 401 goes to authentication 403 goes to forbidden.

@rhutchison
Copy link
Contributor

LGTM - thank you.

@trainerbill
Copy link
Contributor Author

@lirantal. This is ready to merge

@lirantal
Copy link
Member

@ilanbiala ?

@mleanos
Copy link
Member

mleanos commented Aug 20, 2015

@trainerbill I pulled this branch and tested. A few things I noticed... Forgive me if you're aware of these issues..

When not signed in, I go to an invalid route. I'm redirected to the Bad Request state. Now if sign in successfully, I'm redirected back to the Bad Request state.

If a 400 status is returned from the server, it redirects to the Bad Request, even if the 400 was caused by an invalid form submission; for instance, incorrect credentials at login.

I saw mention of the issue where the user can add /edit to an article they are viewing & get to that state. However, they are correctly sent to the Forbidden state if they attempt to submit the form. What is the plan with addressing that? Wouldn't we want to just avoid allowing that state transition in the first place? Perhaps, that's outside the scope of this PR.

@trainerbill Overall this looks really good. Thanks.

@trainerbill
Copy link
Contributor Author

@mleanos Thanks for taking it for a test drive. I was actually worried on the bad request 400 interceptor as the backend seems to throw them quite a bit. I am going to remove the 400 interceptor just to get the PR in. The forbidden route and interceptor is what I really want in. @rhutchison any issue with this?

The /edit route will be taken care of by the article refactor PR #800

@rhutchison rhutchison mentioned this pull request Aug 20, 2015
15 tasks
@@ -0,0 +1,23 @@
'use strict';

//Articles service used for communicating with the articles REST endpoints
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove unrelated comment

$locationProvider.html5Mode(true).hashPrefix('!');
}
angular.module(ApplicationConfiguration.applicationModuleName).config(['$locationProvider', '$httpProvider',
function ($locationProvider, $httpProvider) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix indentation

@rhutchison
Copy link
Contributor

LGTM thanks @trainerbill

@mleanos
Copy link
Member

mleanos commented Aug 21, 2015

@trainerbill I see the 400 is removed, so the issue with the invalid form submission is resolved. Thanks.

I'm still seeing that when I get sent to the not-found state, and then login I'm getting redirected back to the not-found state. Were you waiting to handle that in a separate PR?

Other than that everything looks good to me.

removed part of comment as it was unrelated to this PR

This LGTM, and appears to be ready for merging.

@codydaig
Copy link
Member

LGTM

@rhutchison
Copy link
Contributor

@mleanos @trainerbill @codydaig Please review #843

I'm still seeing that when I get sent to the not-found state, and then login I'm getting redirected back to the not-found state. Were you waiting to handle that in a separate PR?

@trainerbill
Copy link
Contributor Author

Don't merge yet. Writing tests

@trainerbill trainerbill force-pushed the UnauthorizedRoute2 branch 2 times, most recently from 58572ce to 3bd74cd Compare August 24, 2015 20:04
@trainerbill
Copy link
Contributor Author

@lirantal @rhutchison Ready to merge

Added Auth Interceptor tests

cleaned up test

Update routes
@rhutchison
Copy link
Contributor

LGTM

@lirantal lirantal assigned lirantal and unassigned ilanbiala Aug 25, 2015
lirantal added a commit that referenced this pull request Aug 25, 2015
@lirantal lirantal merged commit 2b015b0 into meanjs:master Aug 25, 2015
@ilanbiala ilanbiala modified the milestones: 0.4.1, 0.4.x Aug 31, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants