login works so far
This commit is contained in:
@ -19,7 +19,7 @@ export class ErrorHandlerInterceptor implements HttpInterceptor {
|
||||
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
|
||||
return next.handle(request).pipe(
|
||||
catchError((errorResponse: HttpErrorResponse) => {
|
||||
this.messageService.add(`Intercepted http error: ${errorResponse}`)
|
||||
this.messageService.add(`Intercepted http error: ${JSON.stringify(errorResponse, undefined, 4)}`)
|
||||
if (errorResponse.status === 401) {
|
||||
this.router.navigateByUrl('/login')
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
mat-card {
|
||||
max-width: 400px;
|
||||
margin: 2em auto;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
mat-form-field {
|
||||
display: block;
|
||||
}
|
@ -41,6 +41,7 @@ export class LoginComponent implements OnInit {
|
||||
const password = this.form.get('password')?.value;
|
||||
await this.tokenService.login(username, password);
|
||||
} catch (err) {
|
||||
this.messageService.add(`Login err: ${err.message}`)
|
||||
this.loginInvalid = true;
|
||||
}
|
||||
} else {
|
||||
|
@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
|
||||
import { MessageService } from './message.service';
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { UserCreds } from './userCreds'
|
||||
import { ThrowStmt } from '@angular/compiler';
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
@ -26,8 +27,14 @@ export class TokenService {
|
||||
"login": login,
|
||||
"password": password
|
||||
}
|
||||
const token = await this.http.post<String>("https://authservice.hottis.de/token", userCreds).toPromise()
|
||||
this.messageService.add(`Token is ${JSON.stringify(token, undefined, 4)}`)
|
||||
const token = await this.http.post(
|
||||
"https://authservice.hottis.de/token",
|
||||
userCreds,
|
||||
{responseType:'text'}
|
||||
).toPromise()
|
||||
this.messageService.add(`Token is ${token}`)
|
||||
localStorage.setItem(TokenService.Id_Token_Key, token)
|
||||
this.messageService.add("Token saved")
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user