Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$scope and event handling #72

Open
fecabianchi opened this issue Feb 2, 2017 · 3 comments
Open

$scope and event handling #72

fecabianchi opened this issue Feb 2, 2017 · 3 comments

Comments

@fecabianchi
Copy link

Hi, i'm having a issue for days and can't figure out a solution here is the deal...

i write an interceptor for any response error

export default function authenticationInterceptor($q, $rootScope) {
  notAuthenticated: 'auth-not-authenticated'
  return {
    responseError: (response) => {
      $rootScope.$broadcast({
        401: notAuthenticated
      }[response.status], response);
      return $q.reject(response);
    }
  }
}

and broadcast the event auth-not-authenticated

i'm setting up the interceptor on app.config.js

and trying to check on app.controller that way

export default class AppController {
  constructor($scope, $rootScope, $state, authentication) {
    notAuthenticated: 'auth-not-authenticated'
    $scope.$on(notAuthenticated, (event) => {
      authentication.logout();
      $state.go('login')
    })

but i can't make this work... any help?
what is the best way to handling authentication and events?

Thanks in advance.

@phra
Copy link
Member

phra commented Feb 3, 2017

why are you declaring variables with the colon? 😕

@fecabianchi
Copy link
Author

oh, sry, that was a constant and i copy paste just to try a thing... i'm using as a constant and is returning the right value.

@fecabianchi
Copy link
Author

export default function authenticationInterceptor($q, $rootScope, AUTH_EVENTS) {
  return {
    responseError: (response) => {
      $rootScope.$broadcast({
        401: AUTH_EVENTS.notAuthenticated
      }[response.status], response);
      return $q.reject(response);
    }
  }
}
export default class AppController {
  constructor($scope, $rootScope, $state, authentication, AUTH_EVENTS) {
    $scope.$on(AUTH_EVENTS.notAuthenticated, (event) => {
      authentication.logout();
      $state.go('login')
    })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants