Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(login-form): keep user on same page after login (DEV-1158) #788

Merged
merged 2 commits into from Aug 4, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/app/main/action/login-form/login-form.component.ts
Expand Up @@ -8,6 +8,7 @@ import { AuthenticationService } from '../../services/authentication.service';
import { ComponentCommunicationEventService, EmitEvent, Events } from '../../services/component-communication-event.service';
import { DatadogRumService } from '../../services/datadog-rum.service';
import { Session, SessionService } from '../../services/session.service';
import { Location } from '@angular/common';

@Component({
selector: 'app-login-form',
Expand Down Expand Up @@ -103,6 +104,7 @@ export class LoginFormComponent implements OnInit, AfterViewInit {
private _session: SessionService,
private _route: ActivatedRoute,
private _router: Router,
private _location: Location
) {
this.returnUrl = this._route.snapshot.queryParams['returnUrl'];
}
Expand Down Expand Up @@ -158,12 +160,11 @@ export class LoginFormComponent implements OnInit, AfterViewInit {
this.session = this._session.getSession();

this._componentCommsService.emit(new EmitEvent(Events.loginSuccess, true));

// if user hit a page that requires to be logged in, they will have a returnUrl in the url
this.returnUrl = this._route.snapshot.queryParams['returnUrl'];
if (this.returnUrl) {
this._router.navigate([this.returnUrl]);
} else if (!this._route.snapshot.url.length || (this._route.snapshot.url.length && this._route.snapshot.url[0].path === 'login')) { // if user is on "/" or "/login"
} else if (!this._location.path() || (this._route.snapshot.url.length && this._route.snapshot.url[0].path === 'login')) { // if user is on "/" or "/login"
const username = this.session.user.name;
this._dspApiConnection.admin.usersEndpoint.getUserByUsername(username).subscribe(
(userResponse: ApiResponseData<UserResponse>) => {
Expand Down