import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core'
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core'
-import { ActivatedRoute } from '@angular/router'
-import { AuthService, Notifier, RedirectService, UserService } from '@app/core'
+import { ActivatedRoute, Router } from '@angular/router'
+import { AuthService, Notifier, RedirectService, SessionStorageService, UserService } from '@app/core'
import { HooksService } from '@app/core/plugins/hooks.service'
import { LOGIN_PASSWORD_VALIDATOR, LOGIN_USERNAME_VALIDATOR } from '@app/shared/form-validators/login-validators'
import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
import { InstanceAboutAccordionComponent } from '@app/shared/shared-instance'
import { NgbAccordion, NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
import { HooksService } from '@app/core/plugins/hooks.service'
import { LOGIN_PASSWORD_VALIDATOR, LOGIN_USERNAME_VALIDATOR } from '@app/shared/form-validators/login-validators'
import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
import { InstanceAboutAccordionComponent } from '@app/shared/shared-instance'
import { NgbAccordion, NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
private userService: UserService,
private redirectService: RedirectService,
private notifier: Notifier,
private userService: UserService,
private redirectService: RedirectService,
private notifier: Notifier,
const { username, password } = this.form.value
this.authService.login(username, password)
const { username, password } = this.form.value
this.authService.login(username, password)
const message = $localize`An email with the reset password instructions will be sent to ${this.forgotPasswordEmail}.
The link will expire within 1 hour.`
const message = $localize`An email with the reset password instructions will be sent to ${this.forgotPasswordEmail}.
The link will expire within 1 hour.`
this.isAuthenticatedWithExternalAuth = true
this.authService.login(username, null, token)
this.isAuthenticatedWithExternalAuth = true
this.authService.login(username, null, token)
- .subscribe(
- () => this.redirectService.redirectToPreviousRoute(),
-
- err => {
- this.handleError(err)
- this.isAuthenticatedWithExternalAuth = false
- }
- )
+ .subscribe({
+ next: () => {
+ const redirectUrl = this.storage.getItem(LoginComponent.SESSION_STORAGE_REDIRECT_URL_KEY)
+ if (redirectUrl) {
+ this.storage.removeItem(LoginComponent.SESSION_STORAGE_REDIRECT_URL_KEY)
+ return this.router.navigateByUrl(redirectUrl)
+ }
+
+ this.redirectService.redirectToLatestSessionRoute()
+ },
+
+ error: err => {
+ this.handleError(err)
+ this.isAuthenticatedWithExternalAuth = false
+ }
+ })