Invitation fix.

Fixing  issue when user opens invitation without being logged id.
This commit is contained in:
Kristian Ntavidi 2021-05-11 11:50:25 +03:00
parent b76a787972
commit 29ad55b3f8
1 changed files with 21 additions and 2 deletions

View File

@ -1,5 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { AuthService } from '@app/core/services/auth/auth.service';
import { DmpInvitationService } from '@app/core/services/dmp/dmp-invitation.service';
import { BaseComponent } from '@common/base/base.component';
import { takeUntil } from 'rxjs/operators';
@ -13,19 +14,37 @@ export class InvitationAcceptedComponent extends BaseComponent implements OnInit
constructor(
private dmpInvitationService: DmpInvitationService,
private route: ActivatedRoute,
private router: Router
private router: Router,
private authentication: AuthService,
) { super(); }
ngOnInit(): void {
this.route.params
.pipe(takeUntil(this._destroyed))
.subscribe(params => {
const id = params['id'];
this.dmpInvitationService.exchange(id)
if(this.isAuthenticated()){
this.dmpInvitationService.exchange(id)
.pipe(takeUntil(this._destroyed))
.subscribe(result => {
this.router.navigate(['plans/edit/' + result]);
});
}else{
this.router.navigate(['/login'], {queryParams:{returnUrl:'plans/invitation/'+id}});
}
});
}
public isAuthenticated(): boolean {
return !(!this.authentication.current());
}
}