git init v2

This commit is contained in:
2025-03-11 23:13:19 +01:00
parent 4d4c8a362a
commit abae328d8f
62 changed files with 3461 additions and 421 deletions

View File

@@ -0,0 +1,42 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { JwtHelperService } from '@auth0/angular-jwt';
import { Observable } from 'rxjs';
import {jwtDecode} from 'jwt-decode';
@Injectable({
providedIn: 'root',
})
export class AuthService {
private baseApi = 'http://localhost:8080/api/auth/login';
// baseApi = "https://api.melvanveen.nl/api/auth/login";
jwtHelper = new JwtHelperService();
constructor(private http: HttpClient) {}
login(username: string, password: string): Observable<any> {
return this.http.post(this.baseApi, { username, password });
}
isAuthenticated(): boolean {
const token = localStorage.getItem('token');
return token !== null && !this.jwtHelper.isTokenExpired(token);
}
logout(): void {
localStorage.removeItem('token');
}
getToken(): string | null {
return localStorage.getItem('token');
}
getUserInfo(): any {
const token = this.getToken();
if (token) {
return jwtDecode(token);
}
return null;
}
}