X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fcore%2Fauth%2Fauth.service.ts;h=ed7eabb76c5442dae30e1379b9b04d96b24603e7;hb=2570fd9c1c879d1a543fb0dff1e7cfb036234d11;hp=4de28e51e9d95ee53c969b882e53065a43e617ca;hpb=60b880acdfa85eab5c9ec09ba1283f82ae58ec85;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/core/auth/auth.service.ts b/client/src/app/core/auth/auth.service.ts index 4de28e51e..ed7eabb76 100644 --- a/client/src/app/core/auth/auth.service.ts +++ b/client/src/app/core/auth/auth.service.ts @@ -5,10 +5,11 @@ import { HttpClient, HttpErrorResponse, HttpHeaders, HttpParams } from '@angular import { Injectable } from '@angular/core' import { Router } from '@angular/router' import { Notifier } from '@app/core/notification/notifier.service' -import { logger, OAuthUserTokens, objectToUrlEncoded, peertubeLocalStorage } from '@root-helpers/index' +import { logger, OAuthUserTokens, objectToUrlEncoded, peertubeLocalStorage, PluginsManager } from '@root-helpers/index' import { HttpStatusCode, MyUser as UserServerModel, OAuthClientLocal, User, UserLogin, UserRefreshToken } from '@shared/models' import { environment } from '../../../environments/environment' import { RestExtractor } from '../rest/rest-extractor.service' +import { ServerService } from '../server' import { AuthStatus } from './auth-status.model' import { AuthUser } from './auth-user.model' @@ -44,6 +45,7 @@ export class AuthService { private refreshingTokenObservable: Observable constructor ( + private serverService: ServerService, private http: HttpClient, private notifier: Notifier, private hotkeysService: HotkeysService, @@ -213,25 +215,28 @@ Ensure you have correctly configured PeerTube (config/ directory), in particular const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded') this.refreshingTokenObservable = this.http.post(AuthService.BASE_TOKEN_URL, body, { headers }) - .pipe( - map(res => this.handleRefreshToken(res)), - tap(() => { - this.refreshingTokenObservable = null - }), - catchError(err => { - this.refreshingTokenObservable = null - - logger.error(err) - logger.info('Cannot refresh token -> logout...') - this.logout() - this.router.navigate([ '/login' ]) - - return observableThrowError(() => ({ - error: $localize`You need to reconnect.` - })) - }), - share() - ) + .pipe( + map(res => this.handleRefreshToken(res)), + tap(() => { + this.refreshingTokenObservable = null + }), + catchError(err => { + this.refreshingTokenObservable = null + + logger.error(err) + logger.info('Cannot refresh token -> logout...') + this.logout() + + const externalLoginUrl = PluginsManager.getDefaultLoginHref(environment.apiUrl, this.serverService.getHTMLConfig()) + if (externalLoginUrl) window.location.href = externalLoginUrl + else this.router.navigate([ '/login' ]) + + return observableThrowError(() => ({ + error: $localize`You need to reconnect.` + })) + }), + share() + ) return this.refreshingTokenObservable }