aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/app/_services/auth.service.ts
diff options
context:
space:
mode:
authorTAMARA JERINIC <tamara.jerinic@gmail.com>2022-03-09 22:19:52 +0100
committerTAMARA JERINIC <tamara.jerinic@gmail.com>2022-03-09 22:19:52 +0100
commit1ef8894a7ae00ce8c4ded39c82b4c43993cfa923 (patch)
treeea835844fb6acb404806af9d7768f6fc5c0109c4 /frontend/src/app/_services/auth.service.ts
parent2f67bfab8ecc3d565a6940226bd9d42c1a85159b (diff)
parenta95a921478435cc6400236d291281c3d0156a7e1 (diff)
Merge branch 'dev' of http://gitlab.pmf.kg.ac.rs/igrannonica/neuronstellar into dev
Diffstat (limited to 'frontend/src/app/_services/auth.service.ts')
-rw-r--r--frontend/src/app/_services/auth.service.ts31
1 files changed, 31 insertions, 0 deletions
diff --git a/frontend/src/app/_services/auth.service.ts b/frontend/src/app/_services/auth.service.ts
new file mode 100644
index 00000000..7129b95b
--- /dev/null
+++ b/frontend/src/app/_services/auth.service.ts
@@ -0,0 +1,31 @@
+import { Injectable } from '@angular/core';
+import { HttpClient, HttpHeaders } from '@angular/common/http';
+import { JwtHelperService } from '@auth0/angular-jwt';
+import { CookieService } from 'ngx-cookie-service';
+import { API_SETTINGS } from 'src/config';
+
+const jwtHelper = new JwtHelperService();
+
+@Injectable({
+ providedIn: 'root'
+})
+export class AuthService {
+
+ constructor(private http: HttpClient, private cookie: CookieService) { }
+
+ login(username: string, password: string) {
+ return this.http.post(`${API_SETTINGS.apiURL}/auth/login`, { username, password }, { responseType: 'text' });
+ }
+
+ register(user: any) {
+ return this.http.post(`${API_SETTINGS.apiURL}/auth/register`, user);
+ }
+
+ isAuthenticated(): boolean {
+ if (this.cookie.check('token')) {
+ var token = this.cookie.get('token');
+ return !jwtHelper.isTokenExpired(token);
+ }
+ return false;
+ }
+}