Skip to content

Commit 1730092

Browse files
khasinskiwitoldsz
authored andcommitted
loginCancelled added to authService (abandons or rejects all the requests and broadcasts event:auth-loginCancelled)
1 parent fda0e07 commit 1730092

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/http-auth-interceptor.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
.factory('authService', ['$rootScope','httpBuffer', function($rootScope, httpBuffer) {
1414
return {
1515
/**
16-
* call this function to indicate that authentication was successfull and trigger a
16+
* Call this function to indicate that authentication was successfull and trigger a
1717
* retry of all deferred requests.
1818
* @param data an optional argument to pass on to $broadcast which may be useful for
1919
* example if you need to pass through details of the user that was logged in
@@ -22,6 +22,17 @@
2222
var updater = configUpdater || function(config) {return config;};
2323
$rootScope.$broadcast('event:auth-loginConfirmed', data);
2424
httpBuffer.retryAll(updater);
25+
},
26+
27+
/**
28+
* Call this function to indicate that authentication should not proceed.
29+
* All deferred requests will be abandoned or rejected (if reason is provided).
30+
* @param data an optional argument to pass on to $broadcast.
31+
* @param reason if provided, the requests are rejected; abandoned otherwise.
32+
*/
33+
loginCancelled: function(data, reason) {
34+
httpBuffer.rejectAll(reason);
35+
$rootScope.$broadcast('event:auth-loginCancelled', data);
2536
}
2637
};
2738
}])
@@ -91,6 +102,18 @@
91102
});
92103
},
93104

105+
/**
106+
* Abandon or reject (if reason provided) all the buffered requests.
107+
*/
108+
rejectAll: function(reason) {
109+
if (reason) {
110+
for (var i = 0; i < buffer.length; ++i) {
111+
buffer[i].deferred.reject(reason);
112+
}
113+
}
114+
buffer = [];
115+
},
116+
94117
/**
95118
* Retries all the buffered requests clears the buffer.
96119
*/

0 commit comments

Comments
 (0)