mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-10 03:23:07 +00:00
fixed redirect after login
This commit is contained in:
@@ -56,7 +56,6 @@ export class SearchFiltersComponent {
|
||||
* @returns {Observable<boolean>} Emits true whenever a given filter config should be shown
|
||||
*/
|
||||
isActive(filter: SearchFilterConfig): Observable<boolean> {
|
||||
// console.log(filter.name);
|
||||
return this.filterService.getSelectedValuesForFilter(filter)
|
||||
.flatMap((isActive) => {
|
||||
if (isNotEmpty(isActive)) {
|
||||
|
@@ -107,7 +107,7 @@ export class AuthService {
|
||||
if (status.authenticated) {
|
||||
return status;
|
||||
} else {
|
||||
Observable.throw(new Error('Invalid email or password'));
|
||||
throw(new Error('Invalid email or password'));
|
||||
}
|
||||
})
|
||||
|
||||
@@ -140,7 +140,7 @@ export class AuthService {
|
||||
const person$ = this.rdbService.buildSingle<NormalizedEPerson, EPerson>(status.eperson.toString());
|
||||
return person$.pipe(map((eperson) => eperson.payload));
|
||||
} else {
|
||||
Observable.throw(new Error('Not authenticated'));
|
||||
throw(new Error('Not authenticated'));
|
||||
}
|
||||
}))
|
||||
}
|
||||
@@ -225,7 +225,6 @@ export class AuthService {
|
||||
throw(new Error('auth.errors.invalid-user'));
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -246,6 +245,7 @@ export class AuthService {
|
||||
public getToken(): AuthTokenInfo {
|
||||
let token: AuthTokenInfo;
|
||||
this.store.select(getAuthenticationToken)
|
||||
.first()
|
||||
.subscribe((authTokenInfo: AuthTokenInfo) => {
|
||||
// Retrieve authentication token info and check if is valid
|
||||
token = authTokenInfo || null;
|
||||
@@ -349,8 +349,10 @@ export class AuthService {
|
||||
this.router.navigated = false;
|
||||
const url = decodeURIComponent(redirectUrl);
|
||||
this.router.navigateByUrl(url);
|
||||
this._window.nativeWindow.location.href = url;
|
||||
} else {
|
||||
this.router.navigate(['/']);
|
||||
this._window.nativeWindow.location.href = '/';
|
||||
}
|
||||
})
|
||||
|
||||
|
@@ -44,7 +44,7 @@ export class ServerAuthService extends AuthService {
|
||||
// person$.subscribe(() => console.log('test'));
|
||||
return person$.pipe(map((eperson) => eperson.payload));
|
||||
} else {
|
||||
Observable.throw(new Error('Not authenticated'));
|
||||
throw(new Error('Not authenticated'));
|
||||
}
|
||||
}))
|
||||
}
|
||||
@@ -71,8 +71,10 @@ export class ServerAuthService extends AuthService {
|
||||
this.router.navigated = false;
|
||||
const url = decodeURIComponent(redirectUrl);
|
||||
this.router.navigateByUrl(url);
|
||||
this._window.nativeWindow.location.href = url;
|
||||
} else {
|
||||
this.router.navigate(['/']);
|
||||
this._window.nativeWindow.location.href = '/';
|
||||
}
|
||||
})
|
||||
|
||||
|
@@ -19,6 +19,7 @@ import { HostWindowServiceStub } from '../shared/testing/host-window-service-stu
|
||||
import { RouterStub } from '../shared/testing/router-stub';
|
||||
import { Router } from '@angular/router';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
|
||||
let comp: HeaderComponent;
|
||||
let fixture: ComponentFixture<HeaderComponent>;
|
||||
@@ -35,11 +36,12 @@ describe('HeaderComponent', () => {
|
||||
NgbCollapseModule.forRoot(),
|
||||
NoopAnimationsModule,
|
||||
ReactiveFormsModule],
|
||||
declarations: [HeaderComponent, AuthNavMenuComponent, LoadingComponent, LogInComponent, LogOutComponent],
|
||||
declarations: [HeaderComponent],
|
||||
providers: [
|
||||
{ provide: HostWindowService, useValue: new HostWindowServiceStub(800) },
|
||||
{ provide: Router, useClass: RouterStub },
|
||||
]
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
})
|
||||
.compileComponents(); // compile template and css
|
||||
}));
|
||||
|
@@ -13,7 +13,7 @@ import { HostWindowServiceStub } from '../testing/host-window-service-stub';
|
||||
import { HostWindowService } from '../host-window.service';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { AuthTokenInfo } from '../../core/auth/models/auth-token-info.model';
|
||||
import { EPerson } from '../../core/eperson/models/eperson.model';
|
||||
import { AuthService } from '../../core/auth/auth.service';
|
||||
|
||||
describe('AuthNavMenuComponent', () => {
|
||||
|
||||
@@ -54,6 +54,7 @@ describe('AuthNavMenuComponent', () => {
|
||||
],
|
||||
providers: [
|
||||
{provide: HostWindowService, useValue: window},
|
||||
{provide: AuthService, useValue: {setRedirectUrl: () => {}}}
|
||||
],
|
||||
schemas: [
|
||||
CUSTOM_ELEMENTS_SCHEMA
|
||||
@@ -223,6 +224,7 @@ describe('AuthNavMenuComponent', () => {
|
||||
],
|
||||
providers: [
|
||||
{provide: HostWindowService, useValue: window},
|
||||
{provide: AuthService, useValue: {setRedirectUrl: () => {}}}
|
||||
],
|
||||
schemas: [
|
||||
CUSTOM_ELEMENTS_SCHEMA
|
||||
|
@@ -7,10 +7,14 @@ import { fadeInOut, fadeOut } from '../animations/fade';
|
||||
import { HostWindowService } from '../host-window.service';
|
||||
import { AppState, routerStateSelector } from '../../app.reducer';
|
||||
import { isNotUndefined } from '../empty.util';
|
||||
import { getAuthenticatedUser, isAuthenticated, isAuthenticationLoading } from '../../core/auth/selectors';
|
||||
import {
|
||||
getAuthenticatedUser,
|
||||
isAuthenticated,
|
||||
isAuthenticationLoading
|
||||
} from '../../core/auth/selectors';
|
||||
import { EPerson } from '../../core/eperson/models/eperson.model';
|
||||
import { LOGIN_ROUTE, LOGOUT_ROUTE } from '../../core/auth/auth.service';
|
||||
import { RemoteData } from '../../core/data/remote-data';
|
||||
import { AuthService, LOGIN_ROUTE, LOGOUT_ROUTE } from '../../core/auth/auth.service';
|
||||
import { Subscription } from 'rxjs/Subscription';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-auth-nav-menu',
|
||||
@@ -37,8 +41,12 @@ export class AuthNavMenuComponent implements OnInit {
|
||||
|
||||
public user: Observable<EPerson>;
|
||||
|
||||
public sub: Subscription;
|
||||
|
||||
constructor(private store: Store<AppState>,
|
||||
private windowService: HostWindowService) {
|
||||
private windowService: HostWindowService,
|
||||
private authService: AuthService
|
||||
) {
|
||||
this.isXsOrSm$ = this.windowService.isXsOrSm();
|
||||
}
|
||||
|
||||
@@ -54,7 +62,12 @@ export class AuthNavMenuComponent implements OnInit {
|
||||
this.showAuth = this.store.select(routerStateSelector)
|
||||
.filter((router: RouterReducerState) => isNotUndefined(router) && isNotUndefined(router.state))
|
||||
.map((router: RouterReducerState) => {
|
||||
return !router.state.url.startsWith(LOGIN_ROUTE) && !router.state.url.startsWith(LOGOUT_ROUTE);
|
||||
const url = router.state.url;
|
||||
const show = !router.state.url.startsWith(LOGIN_ROUTE) && !router.state.url.startsWith(LOGOUT_ROUTE);
|
||||
if (show) {
|
||||
this.authService.setRedirectUrl(url);
|
||||
}
|
||||
return show;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user