aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core/auth/auth.service.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-05-07 18:40:51 +0200
committerChocobozzz <me@florianbigard.com>2018-05-07 18:41:10 +0200
commit47f8de28346a7aa28425265f316dc26bf2376c45 (patch)
treed249ee979f3488f92a2917e7b3b016db08aca8db /client/src/app/core/auth/auth.service.ts
parentfd5e57bbe2accbdb16b6aa65337c5ef44b5bd8fb (diff)
downloadPeerTube-47f8de28346a7aa28425265f316dc26bf2376c45.tar.gz
PeerTube-47f8de28346a7aa28425265f316dc26bf2376c45.tar.zst
PeerTube-47f8de28346a7aa28425265f316dc26bf2376c45.zip
Fix error message on token expiration
Diffstat (limited to 'client/src/app/core/auth/auth.service.ts')
-rw-r--r--client/src/app/core/auth/auth.service.ts32
1 files changed, 20 insertions, 12 deletions
diff --git a/client/src/app/core/auth/auth.service.ts b/client/src/app/core/auth/auth.service.ts
index 69ae3e5e1..6223cde6d 100644
--- a/client/src/app/core/auth/auth.service.ts
+++ b/client/src/app/core/auth/auth.service.ts
@@ -39,6 +39,7 @@ export class AuthService {
39 private clientSecret: string 39 private clientSecret: string
40 private loginChanged: Subject<AuthStatus> 40 private loginChanged: Subject<AuthStatus>
41 private user: AuthUser = null 41 private user: AuthUser = null
42 private refreshingTokenObservable: Observable<any>
42 43
43 constructor ( 44 constructor (
44 private http: HttpClient, 45 private http: HttpClient,
@@ -144,6 +145,8 @@ export class AuthService {
144 } 145 }
145 146
146 refreshAccessToken () { 147 refreshAccessToken () {
148 if (this.refreshingTokenObservable) return this.refreshingTokenObservable
149
147 console.log('Refreshing token...') 150 console.log('Refreshing token...')
148 151
149 const refreshToken = this.getRefreshToken() 152 const refreshToken = this.getRefreshToken()
@@ -157,18 +160,23 @@ export class AuthService {
157 160
158 const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded') 161 const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')
159 162
160 return this.http.post<UserRefreshToken>(AuthService.BASE_TOKEN_URL, body, { headers }) 163 this.refreshingTokenObservable = this.http.post<UserRefreshToken>(AuthService.BASE_TOKEN_URL, body, { headers })
161 .map(res => this.handleRefreshToken(res)) 164 .map(res => this.handleRefreshToken(res))
162 .catch(err => { 165 .do(() => this.refreshingTokenObservable = null)
163 console.error(err) 166 .catch(err => {
164 console.log('Cannot refresh token -> logout...') 167 this.refreshingTokenObservable = null
165 this.logout() 168
166 this.router.navigate(['/login']) 169 console.error(err)
167 170 console.log('Cannot refresh token -> logout...')
168 return Observable.throw({ 171 this.logout()
169 error: 'You need to reconnect.' 172 this.router.navigate([ '/login' ])
170 }) 173
171 }) 174 return Observable.throw({
175 error: 'You need to reconnect.'
176 })
177 })
178
179 return this.refreshingTokenObservable
172 } 180 }
173 181
174 refreshUserInformation () { 182 refreshUserInformation () {