fixed redirect on wrong tenant url
This commit is contained in:
parent
0e2548e44d
commit
ec77117f36
|
@ -43,6 +43,7 @@ import { TenantHandlingService } from './core/services/tenant/tenant-handling.se
|
|||
import { GuidedTourModule } from './library/guided-tour/guided-tour.module';
|
||||
import { DepositOauth2DialogModule } from './ui/misc/deposit-oauth2-dialog/deposit-oauth2-dialog.module';
|
||||
import { OpenCDMPCustomTranslationCompiler } from './utilities/translate/opencdmp-custom-translation-compiler';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
// AoT requires an exported function for factories
|
||||
export function HttpLoaderFactory(languageHttpService: LanguageHttpService) {
|
||||
|
@ -79,7 +80,7 @@ const cookieConfig: NgcCookieConsentConfig = {
|
|||
type: 'info'
|
||||
};
|
||||
|
||||
export function InstallationConfigurationFactory(appConfig: ConfigurationService, keycloak: KeycloakService, authService: AuthService, languageService: LanguageService, tenantHandlingService: TenantHandlingService) {
|
||||
export function InstallationConfigurationFactory(appConfig: ConfigurationService, keycloak: KeycloakService, authService: AuthService, languageService: LanguageService, tenantHandlingService: TenantHandlingService, router: Router) {
|
||||
return () => appConfig.loadConfiguration().then(() => {
|
||||
return languageService.loadAvailableLanguages().toPromise();
|
||||
}).then(x => keycloak.init({
|
||||
|
@ -109,7 +110,14 @@ export function InstallationConfigurationFactory(appConfig: ConfigurationService
|
|||
|
||||
const tenantCode = tenantHandlingService.extractTenantCodeFromUrlPath(window.location.pathname) ?? authService.selectedTenant() ?? 'default';
|
||||
const tokenPromise = keycloak.getToken();
|
||||
return authService.prepareAuthRequest(from(tokenPromise), tenantCode, { params }).toPromise().catch(error => authService.onAuthenticateError(error));
|
||||
return authService.prepareAuthRequest(from(tokenPromise), tenantCode, { params })
|
||||
.toPromise()
|
||||
.then(() => {
|
||||
if (authService.selectedTenant() != tenantCode) {
|
||||
router.navigate(['/']);
|
||||
}
|
||||
})
|
||||
.catch(error => authService.onAuthenticateError(error));
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -157,7 +165,7 @@ export function InstallationConfigurationFactory(appConfig: ConfigurationService
|
|||
{
|
||||
provide: APP_INITIALIZER,
|
||||
useFactory: InstallationConfigurationFactory,
|
||||
deps: [ConfigurationService, KeycloakService, AuthService, LanguageService, TenantHandlingService],
|
||||
deps: [ConfigurationService, KeycloakService, AuthService, LanguageService, TenantHandlingService, Router],
|
||||
multi: true
|
||||
},
|
||||
{
|
||||
|
|
|
@ -174,7 +174,6 @@ export class AuthService extends BaseService {
|
|||
return this.ensureTenant(tenantCode ?? this.selectedTenant() ?? 'default');
|
||||
}),
|
||||
concatMap(response => {
|
||||
if (response == 'default' && tenantCode != 'default') throw Error();
|
||||
return this.principalService.me(httpParams);
|
||||
}),
|
||||
concatMap(response => {
|
||||
|
|
|
@ -40,6 +40,9 @@ export class LoginComponent extends BaseComponent implements OnInit {
|
|||
this.authService.prepareAuthRequest(from(this.keycloakService.getToken()), tenantCode).pipe(takeUntil(this._destroyed)).subscribe(
|
||||
() => {
|
||||
let returnUrL = this.returnUrl;
|
||||
|
||||
if (this.authService.selectedTenant() != tenantCode) returnUrL = this.routerUtils.generateUrl('/');
|
||||
|
||||
this.zone.run(() => this.router.navigateByUrl(this.routerUtils.generateUrl(returnUrL)));
|
||||
},
|
||||
(error) => this.authService.authenticate('/'));
|
||||
|
|
Loading…
Reference in New Issue