-import { environment } from 'src/environments/environment'
+
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core'
import { ActivatedRoute } from '@angular/router'
-import { AuthService, Notifier, RedirectService, UserService } from '@app/core'
+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 { PluginsManager } from '@root-helpers/plugins-manager'
import { RegisteredExternalAuthConfig, ServerConfig } from '@shared/models'
@Component({
})
export class LoginComponent extends FormReactive implements OnInit, AfterViewInit {
+ private static SESSION_STORAGE_REDIRECT_URL_KEY = 'login-previous-url'
+
@ViewChild('forgotPasswordModal', { static: true }) forgotPasswordModal: ElementRef
accordion: NgbAccordion
private userService: UserService,
private redirectService: RedirectService,
private notifier: Notifier,
- private hooks: HooksService
+ private hooks: HooksService,
+ private storage: SessionStorageService
) {
super()
}
this.externalAuthError = true
return
}
+
+ this.storage.setItem(LoginComponent.SESSION_STORAGE_REDIRECT_URL_KEY, this.redirectService.getPreviousUrl())
}
ngAfterViewInit () {
}
getAuthHref (auth: RegisteredExternalAuthConfig) {
- return environment.apiUrl + `/plugins/${auth.name}/${auth.version}/auth/${auth.authName}`
+ return PluginsManager.getExternalAuthHref(auth)
}
login () {
this.authService.login(username, null, token)
.subscribe({
- next: () => this.redirectService.redirectToPreviousRoute(),
+ next: () => {
+ this.redirectService.redirectToPreviousRoute(this.storage.getItem(LoginComponent.SESSION_STORAGE_REDIRECT_URL_KEY))
+ },
error: err => {
this.handleError(err)