ng-token-auth
ng-token-auth copied to clipboard
$auth.validateUser({ config: 'my_other_model' }) not working properly
version 0.0.28
My config:
$authProvider.configure([
{
default: {
apiUrl: settings.apiUrl,
storage: 'localStorage',
validateOnPageLoad: false
}
},
{
shopkeeper: {
apiUrl: settings.apiUrl,
signOutUrl: '/shopkeeper_auth/sign_out',
emailSignInPath: '/shopkeeper_auth/sign_in',
emailRegistrationPath: '/shopkeeper_auth',
accountUpdatePath: '/shopkeeper_auth',
accountDeletePath: '/shopkeeper_auth',
passwordResetPath: '/shopkeeper_auth/password',
passwordUpdatePath: '/shopkeeper_auth/password',
tokenValidationPath: '/shopkeeper_auth/validate_token',
storage: 'localStorage',
validateOnPageLoad: false
}
}
]);
Then I logged in with default user.
$auth.submitLogin({
email: $scope.email,
password: $scope.password
});
my controller:
$auth.validateUser( { config: 'shopkeeper' } ).then( logResponse ).catch( logResponse );
function logResponse( response ){
console.log( response );
}
and result:
[Log] Object (controller.js, line 12)
configName: "default"
email: "[email protected]"
id: 6
nome: "Stephann Vasconcelos"
provider: "email"
signedIn: true
uid: "[email protected]"
__proto__: Object
I'm confused. On read me:
$auth.validateUser This method returns a promise that will resolve if a user's auth token exists and is valid. This method does not accept any arguments.
Later on read me:
The following API methods accept a config option that can be used to specify the desired configuration.
$auth.authenticate $auth.validateUser $auth.submitRegistration $auth.submitLogin $auth.requestPasswordReset All other methods ($auth.signOut, $auth.updateAccount, etc.) derive the configuration type from the current signed-in user.
I have the same problem, looks like the config argument is ignored in validateUser function: https://github.com/lynndylanhurley/ng-token-auth/blob/master/src/ng-token-auth.coffee#L488
My workaround: I'm validating without 'config' and checking the response's configName
$auth.validateUser().then( function( response ) {
if( response.configName == 'shopkeeper' ){
//redirect to 403 forbidden
};
});
I also noticed that the persistence methods for deleting and retrieving do not take configName into account. Linking to the JS since my coffee is not very good looking: retriveData deleteData