ActivityPub-federated video streaming platform using P2P directly in your web browser
Reload page after login to respect user lang
Chocobozzzc211247f5069
diff --git a/client/src/app/+login/login.component.ts b/client/src/app/+login/login.component.tsindex 9a554c7244..09b41937ef 100644--- a/client/src/app/+login/login.component.ts+++ b/client/src/app/+login/login.component.ts@@ -1,5 +1,5 @@import { NgClass } from '@angular/common'-import { AfterViewInit, Component, ElementRef, OnInit, inject, viewChild } from '@angular/core'+import { AfterViewInit, Component, ElementRef, LOCALE_ID, OnInit, inject, viewChild } from '@angular/core'import { FormsModule, ReactiveFormsModule } from '@angular/forms'import { ActivatedRoute, Router, RouterLink } from '@angular/router'import { AuthService, Notifier, RedirectService, SessionStorageService, UserService } from '@app/core'@@ -12,8 +12,9 @@ import { InputTextComponent } from '@app/shared/shared-forms/input-text.componenimport { InstanceAboutAccordionComponent } from '@app/shared/shared-instance/instance-about-accordion.component'import { AlertComponent } from '@app/shared/shared-main/common/alert.component'import { NgbAccordionDirective, NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'-import { getExternalAuthHref } from '@peertube/peertube-core-utils'+import { getCompleteLocale, getExternalAuthHref } from '@peertube/peertube-core-utils'import { RegisteredExternalAuthConfig, ServerConfig, ServerErrorCode } from '@peertube/peertube-models'+import { of, switchMap } from 'rxjs'import { environment } from 'src/environments/environment'import { GlobalIconComponent } from '../shared/shared-icons/global-icon.component'import { InstanceBannerComponent } from '../shared/shared-instance/instance-banner.component'@@ -49,6 +50,7 @@ export class LoginComponent extends FormReactive implements OnInit, AfterViewIniprivate hooks = inject(HooksService)private storage = inject(SessionStorageService)private router = inject(Router)+ private localeId = inject(LOCALE_ID)private static SESSION_STORAGE_REDIRECT_URL_KEY = 'login-previous-url'@@ -162,9 +164,12 @@ export class LoginComponent extends FormReactive implements OnInit, AfterViewIni}this.authService.login(options)- .pipe()+ .pipe(+ switchMap(() => this.authService.userInformationLoaded),+ switchMap(() => this.updateUserLanguageIfNeeded())+ ).subscribe({- next: () => this.redirectService.redirectToPreviousRoute(),+ next: () => this.redirectService.redirectToPreviousRoute({ reloadTab: this.shouldReloadTabOnLogin() }),error: err => {this.handleError(err)@@ -203,6 +208,10 @@ The link will expire within 1 hour.`this.isAuthenticatedWithExternalAuth = truethis.authService.login({ username, password: null, token })+ .pipe(+ switchMap(() => this.authService.userInformationLoaded),+ switchMap(() => this.updateUserLanguageIfNeeded())+ ).subscribe({next: () => {const redirectUrl = this.storage.getItem(LoginComponent.SESSION_STORAGE_REDIRECT_URL_KEY)@@ -211,7 +220,7 @@ The link will expire within 1 hour.`return this.router.navigateByUrl(redirectUrl)}- this.redirectService.redirectToLatestSessionRoute()+ this.redirectService.redirectToLatestSessionRoute({ reloadTab: this.shouldReloadTabOnLogin() })},error: err => {@@ -255,4 +264,18 @@ The link will expire within 1 hour.`this.error = err.message}++ private shouldReloadTabOnLogin () {+ const user = this.authService.getUser()++ return user.language && getCompleteLocale(user.language) !== getCompleteLocale(this.localeId)+ }++ private updateUserLanguageIfNeeded () {+ if (this.authService.getUser().language) {+ return this.userService.updateInterfaceLanguage(this.authService.getUser().language)+ }++ return of(true)+ }}diff --git a/client/src/app/core/routing/redirect.service.ts b/client/src/app/core/routing/redirect.service.tsindex f57bd2b08d..c2baac1d4a 100644--- a/client/src/app/core/routing/redirect.service.ts+++ b/client/src/app/core/routing/redirect.service.ts@@ -89,21 +89,35 @@ export class RedirectService {}}- redirectToLatestSessionRoute () {- return this.doRedirect(this.latestSessionUrl)+ redirectToLatestSessionRoute (options: {+ reloadTab?: boolean+ } = {}) {+ return this.doRedirect(this.latestSessionUrl, options)}- redirectToPreviousRoute (fallbackRoute?: string) {- return this.doRedirect(this.previousUrl, fallbackRoute)+ redirectToPreviousRoute (options: {+ reloadTab?: boolean+ } = {}) {+ return this.doRedirect(this.previousUrl, options)}getPreviousUrl () {return this.previousUrl}- redirectToHomepage (skipLocationChange = false) {+ redirectToHomepage (options: {+ skipLocationChange?: boolean // default false+ reloadTab?: boolean // default false+ } = {}) {+ const { skipLocationChange = false, reloadTab = false } = options+if (this.redirectingToHomepage) return+ if (reloadTab) {+ window.location.href = this.defaultRoute+ return+ }+this.redirectingToHomepage = truelogger.info(`Redirecting to default route ${this.defaultRoute}...`, { skipLocationChange })@@ -131,20 +145,24 @@ export class RedirectService {this.router.navigate([ '/401' ], { state: { obj: err }, skipLocationChange: true })}- private doRedirect (redirectUrl: string, fallbackRoute?: string) {+ private doRedirect (redirectUrl: string, options: {+ reloadTab?: boolean+ } = {}) {+ const { reloadTab = false } = options+debugLogger('Redirecting on %s', redirectUrl)if (this.isValidRedirection(redirectUrl)) {- return this.router.navigateByUrl(redirectUrl)- }+ if (reloadTab) {+ window.location.href = redirectUrl+ return+ }- debugLogger('%s is not a valid redirection, try fallback route %s', redirectUrl, fallbackRoute)- if (fallbackRoute) {- return this.router.navigateByUrl(fallbackRoute)+ return this.router.navigateByUrl(redirectUrl)}- debugLogger('There was no fallback route, redirecting to homepage')- return this.redirectToHomepage()+ debugLogger(`${redirectUrl} is not a valid redirection, redirecting to homepage`)+ return this.redirectToHomepage(options)}private isValidRedirection (redirectUrl: string) {diff --git a/client/src/app/homepage-redirect.component.ts b/client/src/app/homepage-redirect.component.tsindex 98f06d64fd..f76f8477f7 100644--- a/client/src/app/homepage-redirect.component.ts+++ b/client/src/app/homepage-redirect.component.ts@@ -22,7 +22,7 @@ export class HomepageRedirectComponent implements OnInit {const url = this.route.snapshot.urlif (url.length === 0 || is18nPath('/' + url[0])) {- this.redirectService.redirectToHomepage(true)+ this.redirectService.redirectToHomepage({ skipLocationChange: true })}}}