Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Dockerfile path. #6

Merged
merged 15 commits into from
Oct 4, 2022
Merged
Prev Previous commit
Next Next commit
print error messages during login/signup.
  • Loading branch information
AnalogJ committed Sep 28, 2022
commit cb431a95ffd1fba35a2b843d9cfb97f94465b88b
14 changes: 7 additions & 7 deletions frontend/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ export class AppComponent implements OnInit {
navbarBackdrop.classList.add('az-navbar-backdrop');
document.querySelector('body').appendChild(navbarBackdrop);

//TODO: onfirst load the header is always shown, why?
// seems to be related to the presence of jwt token, and/or auth-interceptor.
//determine if we should show the header
this.router.events.subscribe(event => this.modifyHeader(event));
}

modifyHeader(event) {
if(event instanceof NavigationEnd && event.url?.startsWith('/auth'))
{
this.showHeader = false;
} else {
this.showHeader = true;
if (event instanceof NavigationEnd) {
if (event.url?.startsWith('/auth')) {
this.showHeader = false;
} else {
// console.log("NU")
this.showHeader = true;
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/app/pages/auth-signin/auth-signin.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ <h4>Please sign in to continue</h4>
</div><!-- form-group -->
<button [disabled]="!userForm.form.valid" type="submit" class="btn btn-az-primary btn-block">Sign In</button>

<div *ngIf="errorMsg" class="alert alert-danger mt-3" role="alert">
<strong>Error</strong> {{errorMsg}}
</div>
</form>
</div><!-- az-signin-header -->
<div class="az-signin-footer">
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/app/pages/auth-signin/auth-signin.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {Router} from '@angular/router';
export class AuthSigninComponent implements OnInit {
submitted: boolean = false
existingUser: User = new User()
errorMsg: string = ""

constructor(private fastenApi: FastenApiService, private router: Router) { }

Expand All @@ -22,8 +23,9 @@ export class AuthSigninComponent implements OnInit {

this.fastenApi.signin(this.existingUser.username, this.existingUser.password).subscribe((tokenResp: any) => {
console.log(tokenResp);

this.router.navigateByUrl('/dashboard');
}, (err)=>{
this.errorMsg = err?.error?.error || "an unknown error occurred during sign-in"
})
}
}
4 changes: 4 additions & 0 deletions frontend/src/app/pages/auth-signup/auth-signup.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ <h4>Create an account, and get started.</h4>
</div>
</div><!-- form-group -->
<button [disabled]="!userForm.form.valid" type="submit" class="btn btn-az-primary btn-block">Create Account</button>

<div *ngIf="errorMsg" class="alert alert-danger mt-3" role="alert">
<strong>Error</strong> {{errorMsg}}
</div>
</form>
</div><!-- az-signup-header -->
<div class="az-signup-footer">
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/app/pages/auth-signup/auth-signup.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {Router} from '@angular/router';
export class AuthSignupComponent implements OnInit {
submitted: boolean = false
newUser: User = new User()
errorMsg: string = ""

constructor(private fastenApi: FastenApiService, private router: Router) { }

Expand All @@ -25,7 +26,10 @@ export class AuthSignupComponent implements OnInit {
console.log(tokenResp);

this.router.navigateByUrl('/dashboard');
})
},
(err)=>{
this.errorMsg = err?.error?.error || "an unknown error occurred during sign-up"
})
}

}
17 changes: 13 additions & 4 deletions frontend/src/app/services/fasten-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ export class FastenApiService {
signup(newUser: User): Observable<any> {
return this._httpClient.post<any>(`${this.getBasePath()}/api/auth/signup`, newUser).pipe(
map((res: any) => {
localStorage.setItem(this.AUTH_TOKEN_KEY, res.data);
return res.data
if(res.success){
localStorage.setItem(this.AUTH_TOKEN_KEY, res.data);
return res.data
} else {
throw new Error(res.error)
}

}
));
}
Expand All @@ -58,8 +63,12 @@ export class FastenApiService {

return this._httpClient.post<any>(`${this.getBasePath()}/api/auth/signin`, data).pipe(
map((res: any) => {
localStorage.setItem(this.AUTH_TOKEN_KEY, res.data);
return res.data
if(res.success){
localStorage.setItem(this.AUTH_TOKEN_KEY, res.data);
return res.data
} else {
throw new Error(res.error)
}
}
));
}
Expand Down