]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
feat: custom msg upon 401 response
authorkontrollanten <6680299+kontrollanten@users.noreply.github.com>
Mon, 4 Jul 2022 20:04:55 +0000 (22:04 +0200)
committerChocobozzz <me@florianbigard.com>
Fri, 8 Jul 2022 08:58:04 +0000 (10:58 +0200)
closes #4768

client/src/app/+page-not-found/page-not-found.component.html
client/src/app/core/routing/redirect.service.ts
client/src/app/shared/shared-main/auth/auth-interceptor.service.ts

index 70ede26e8327fdc830fb4e6941b0b9c995c78de4..c6ca8670e5e5e5cd370b0739b9fc191a6a2f60ec 100644 (file)
@@ -1,5 +1,5 @@
 <div class="root">
-  <div *ngIf="status !== 403 && status !== 418" class="box">
+  <div *ngIf="status !== 401 && status !== 403 && status !== 418" class="box">
     <strong>{{ status }}.</strong>
     <span class="ms-1 muted" i18n>That's an error.</span>
 
     </div>
   </div>
 
+  <div *ngIf="status === 401" class="box">
+    <strong>{{ status }}.</strong>
+    <span class="ms-1 muted" i18n>You are not authorized here.</span>
+
+    <div class="text mt-4">
+      <ng-container *ngIf="type === 'video'" i18n>You might need to login to see the video.</ng-container>
+      <ng-container *ngIf="type !== 'video'" i18n>You might need to login to see the resource.</ng-container>
+    </div>
+
+    <a class="peertube-button-link orange-button mt-5" i18n routerLink="/login">
+      Login
+    </a>
+
+  </div>
+
   <div *ngIf="status === 403" class="box">
     <strong>{{ status }}.</strong>
     <span class="ms-1 muted" i18n>You are not authorized here.</span>
index 2b8cbaa59f72df2448a033e733881a48a074cca6..db4b3501862f6986efd036fa09473d028d966ab1 100644 (file)
@@ -46,6 +46,8 @@ export class RedirectService {
     this.currentUrl = this.router.url
     router.events.subscribe(event => {
       if (event instanceof NavigationEnd || event instanceof NavigationCancel) {
+        if (event.url === '/404') return
+
         this.previousUrl = this.currentUrl
         this.currentUrl = event.url
 
index 51248c7b26e5e0920c8dbe95ccdeffff1b8aedc4..7daf31a981c1092ad51788f9478574f8fe602f7d 100644 (file)
@@ -61,8 +61,8 @@ export class AuthInterceptor implements HttpInterceptor {
     return req.clone({ headers: req.headers.set('Authorization', authHeaderValue) })
   }
 
-  private handleNotAuthenticated (err: HttpErrorResponse, path = '/login'): Observable<any> {
-    this.router.navigateByUrl(path)
+  private handleNotAuthenticated (err: HttpErrorResponse): Observable<any> {
+    this.router.navigate([ '/404' ], { state: { obj: err }, skipLocationChange: true })
     return of(err.message)
   }
 }