@@ -158,20 +158,33 @@ export class OAuthService extends AuthConfig {
158
158
159
159
/**
160
160
* Will setup up silent refreshing for when the token is
161
- * about to expire.
161
+ * about to expire. When the user is logged out via this.logOut method, the
162
+ * silent refreshing will pause and not refresh the tokens until the user is
163
+ * logged back in via receiving a new token.
162
164
* @param params Additional parameter to pass
165
+ * @param listenTo Setup automatic refresh of a specific token type
163
166
*/
164
167
public setupAutomaticSilentRefresh ( params : object = { } , listenTo ?: 'access_token' | 'id_token' | 'any' ) {
165
- this . events . pipe ( filter ( e => e . type === 'token_expires' ) ) . subscribe ( e => {
166
- const event = e as OAuthInfoEvent ;
167
- if ( listenTo == null || listenTo === 'any' || event . info === listenTo ) {
168
- this . silentRefresh ( params ) . catch ( _ => {
169
- this . debug ( 'Automatic silent refresh did not work' ) ;
170
- } ) ;
171
- }
172
- } ) ;
168
+ let shouldRunSilentRefresh = true ;
169
+ this . events . pipe (
170
+ tap ( ( e ) => {
171
+ if ( e . type === 'token_received' ) {
172
+ shouldRunSilentRefresh = true ;
173
+ } else if ( e . type === 'logout' ) {
174
+ shouldRunSilentRefresh = false ;
175
+ }
176
+ } ) ,
177
+ filter ( e => e . type === 'token_expires' )
178
+ ) . subscribe ( e => {
179
+ const event = e as OAuthInfoEvent ;
180
+ if ( ( listenTo == null || listenTo === 'any' || event . info === listenTo ) && shouldRunSilentRefresh ) {
181
+ this . silentRefresh ( params ) . catch ( _ => {
182
+ this . debug ( 'Automatic silent refresh did not work' ) ;
183
+ } ) ;
184
+ }
185
+ } ) ;
173
186
174
- this . restartRefreshTimerIfStillLoggedIn ( ) ;
187
+ this . restartRefreshTimerIfStillLoggedIn ( ) ;
175
188
}
176
189
177
190
0 commit comments