Skip to content

Instantly share code, notes, and snippets.

@Bazooka2091
Last active September 3, 2021 04:04
Show Gist options
  • Save Bazooka2091/5689b594c2e15625fbf84f59d87bed61 to your computer and use it in GitHub Desktop.
Save Bazooka2091/5689b594c2e15625fbf84f59d87bed61 to your computer and use it in GitHub Desktop.
Angular
import { Component, OnInit } from '@angular/core';
import { Navigation, Router } from '@angular/router';
import { AuthService } from '../../services/auth/auth.service';
@Component({
selector: 'app-sign-in',
templateUrl: './sign-in.component.html',
styleUrls: ['./sign-in.component.scss'],
})
export class SignInComponent implements OnInit {
private _currentNavigation: Navigation | null;
public url: string | null = '/';
public auth: boolean = false;
public error: string = '';
constructor(private router: Router, private authService: AuthService) {
this._currentNavigation = router.getCurrentNavigation();
}
ngOnInit(): void {
console.log(this._currentNavigation);
const currentRedirect: string = this._currentNavigation?.extras.state?.["url"];
this.url = currentRedirect || '/';
this.auth = this.authService.isLoggedIn();
}
toggleAuth(): void {
this.error = '';
this.authService.toggleAuth();
this.auth = this.authService.isLoggedIn();
}
goToApplication(): void {
if ( this.authService.isLoggedIn() ) {
this.router.navigate([this.url], this._currentNavigation?.extras)
} else {
this.error = 'Ошибка авторизации!';
this.auth = this.authService.isLoggedIn();
}
}
}
// navigation
this.router.navigate(['/']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment