diff --git a/src/app/app.component.html b/src/app/app.component.html
index 82ba9be..b7b8275 100644
--- a/src/app/app.component.html
+++ b/src/app/app.component.html
@@ -27,11 +27,9 @@
-
+
\ No newline at end of file
diff --git a/src/app/app.component.ts b/src/app/app.component.ts
index b7da0b7..ea9a102 100644
--- a/src/app/app.component.ts
+++ b/src/app/app.component.ts
@@ -48,12 +48,8 @@ export class AppComponent implements OnInit , OnDestroy {
ngOnInit (){
this.loginSub = this.authService.loginSuccess.subscribe(
- (item: any) => {
- console.log(item);
- if (item != null)
- this.login = true;
- else
- this.login = false;
+ (success: boolean) => {
+ this.login = success;
}
)
}
diff --git a/src/app/auth/auth.component.html b/src/app/auth/auth.component.html
index b9ad505..334f72f 100644
--- a/src/app/auth/auth.component.html
+++ b/src/app/auth/auth.component.html
@@ -1,7 +1,7 @@
\ No newline at end of file
diff --git a/src/app/auth/auth.component.ts b/src/app/auth/auth.component.ts
index 5576fd4..31083ba 100644
--- a/src/app/auth/auth.component.ts
+++ b/src/app/auth/auth.component.ts
@@ -1,6 +1,7 @@
-import { Component, OnInit } from '@angular/core';
+import { Component, OnDestroy, OnInit } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
+import { Subscription } from 'rxjs';
import { AuthService } from '../service/auth.service';
@@ -9,7 +10,9 @@ import { AuthService } from '../service/auth.service';
templateUrl: './auth.component.html',
styleUrls: ['./auth.component.scss']
})
-export class AuthComponent implements OnInit {
+export class AuthComponent implements OnInit, OnDestroy{
+ loading : boolean ; // a state that user is currently loading loggin
+ loginSub: Subscription;
public userForm: FormGroup = new FormGroup({
password: new FormControl('abcdefg', [Validators.minLength(3), Validators.maxLength(20)]),
@@ -19,13 +22,26 @@ export class AuthComponent implements OnInit {
constructor(private authService: AuthService, private rounter: Router) { }
ngOnInit(): void {
- this.authService.loginSuccess.emit(null);
+ this.loginSub = this.authService.loginSuccess.subscribe(
+ (ok :boolean ) =>{
+ this.loading = false
+ console.log (" found login success " + ok );
+ if (ok)
+ this.rounter.navigate(["/dashboard"]);
+ else
+ alert('fuck this is wrong');
+ }
+ );
+ }
+
+ ngOnDestroy(): void {
+ this.loginSub.unsubscribe();
}
submitForm() {
console.log(this.userForm);
- this.authService.login("email", "pass");
- this.authService.loginSuccess.emit(this.userForm)
- this.rounter.navigate(["/dashboard"]);
+ this.loading = true;
+ this.authService.login(this.userForm.value.email, this.userForm.value.password);
+
}
}
diff --git a/src/app/auth/dist/auth.component.js b/src/app/auth/dist/auth.component.js
index 00110d7..06f7c70 100644
--- a/src/app/auth/dist/auth.component.js
+++ b/src/app/auth/dist/auth.component.js
@@ -19,13 +19,23 @@ var AuthComponent = /** @class */ (function () {
});
}
AuthComponent.prototype.ngOnInit = function () {
- this.authService.loginSuccess.emit(null);
+ var _this = this;
+ this.loginSub = this.authService.loginSuccess.subscribe(function (ok) {
+ _this.loading = false;
+ console.log(" found login success " + ok);
+ if (ok)
+ _this.rounter.navigate(["/dashboard"]);
+ else
+ alert('fuck this is wrong');
+ });
+ };
+ AuthComponent.prototype.ngOnDestroy = function () {
+ this.loginSub.unsubscribe();
};
AuthComponent.prototype.submitForm = function () {
console.log(this.userForm);
- this.authService.login("email", "pass");
- this.authService.loginSuccess.emit(this.userForm);
- this.rounter.navigate(["/dashboard"]);
+ this.loading = true;
+ this.authService.login(this.userForm.value.email, this.userForm.value.password);
};
AuthComponent = __decorate([
core_1.Component({
diff --git a/src/app/service/auth-guard.service.ts b/src/app/service/auth-guard.service.ts
index 931bcb1..3959572 100644
--- a/src/app/service/auth-guard.service.ts
+++ b/src/app/service/auth-guard.service.ts
@@ -12,24 +12,19 @@ import { AuthService } from './auth.service';
@Injectable()
export class AuthGuard implements CanActivate, CanActivateChild {
- constructor(private authService: AuthService, private router: Router) {}
+ constructor(private authService: AuthService, private router: Router) { }
canActivate(route: ActivatedRouteSnapshot,
- state: RouterStateSnapshot): Observable