Skip to content

Commit 43a5c64

Browse files
committed
Merge pull request witoldsz#83 from batoure/DOCUMENTATION-clarify_header_update
Clarified Advanced Use cases
2 parents 79cf2bb + 261484d commit 43a5c64

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,31 @@ the `function(response) {do-something-with-response}` will fire,
4747
* your application will continue as nothing had happened.
4848

4949
###Advanced use case:
50-
Same beginning as before but,
51-
* once your application figures out the authentication is OK, call: `authService.loginConfirmed([data], [updateConfigFunc])`,
52-
* your initial failed request will now be retried but you can supply additional data to observers who are listening for `event:auth-loginConfirmed`, and all your queued http requests will be recalculated by your `updateConfigFunc(httpConfig)` function. This is very usefull if you need to update the headers with new credentials and/or tokens from your successful login.
50+
51+
####Sending data to listeners:
52+
You can supply additional data to observers accross your application who are listening for `event:auth-loginConfirmed`:
53+
54+
$scope.$on('event:auth-loginConfirmed', function(event, data){
55+
$rootScope.isLoggedin = true;
56+
$log.log(data)
57+
});
58+
59+
Use the `authService.loginConfirmed([data])` method to emit data with your login event.
60+
61+
####Updating [$http(config)](https://docs.angularjs.org/api/ng/service/$http):
62+
Successful login means that the previous request are ready to be fired again, however now that login has occured certain aspects of the previous requests might need to be modified on the fly. This is particularly important in a token based authentication scheme where an authorization token should be added to the header.
63+
64+
The `loginConfirmed` method supports the injection of an Updater function that will apply changes to the http config object.
65+
66+
authService.loginConfirmed([data], [Updater-Function])
67+
68+
//application of tokens to previously fired requests:
69+
var token = reponse.token;
70+
71+
authService.loginConfirmed('success', function(config){
72+
config.headers["Authorization"] = token;
73+
return config;
74+
})
75+
76+
The initial failed request will now be retried, all queued http requests will be recalculated using the Updater-Function.
5377

0 commit comments

Comments
 (0)