-
+
@if (loading) {
-
- Signing In...
-
+
Signing In...
}@else {
Sign In
}
diff --git a/client/src/app/screens/screen-login/screen-login.ts b/client/src/app/screens/screen-login/screen-login.ts
index 1cf4f1b..04b90be 100644
--- a/client/src/app/screens/screen-login/screen-login.ts
+++ b/client/src/app/screens/screen-login/screen-login.ts
@@ -1,8 +1,9 @@
import { CommonModule } from '@angular/common';
import { Component } from '@angular/core';
-import { Validators, FormBuilder, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
+import { Validators, FormBuilder, FormGroup, FormsModule, ReactiveFormsModule, Form } from '@angular/forms';
import { Router } from '@angular/router';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
+import { APIService } from '../../services/api';
@Component({
selector: 'app-screen-login',
@@ -18,38 +19,30 @@ export class ScreenLogin {
error: string | null = null;
constructor(
+ private api: APIService,
+ private router: Router,
private fb: FormBuilder,
- private router: Router
) {
this.loginForm = this.fb.group({
- email: ['', [Validators.required, Validators.email]],
- password: ['', [Validators.required, Validators.minLength(6)]],
- rememberMe: [false]
+ username: ['', [Validators.required]],
+ password: ['', [Validators.required]],
});
}
onSubmit() {
this.submitted = true;
this.error = null;
-
- if (this.loginForm.invalid) {
- return;
- }
-
this.loading = true;
- const { email, password, rememberMe } = this.loginForm.value;
- /*
- this.authService.login(email, password, rememberMe).subscribe({
+ this.api.login(this.loginForm.value.username, this.loginForm.value.password).subscribe({
next: () => {
- this.router.navigate(['/dashboard']); // Redirect after login
+ //this.router.navigate(['']);
},
error: (err) => {
this.error = err.error?.message || 'Login failed. Please try again.';
this.loading = false;
}
});
- */
}
}
diff --git a/client/src/app/services/api.ts b/client/src/app/services/api.ts
index db3121e..507b0d8 100644
--- a/client/src/app/services/api.ts
+++ b/client/src/app/services/api.ts
@@ -14,4 +14,7 @@ export class APIService {
getTransactions(): Observable
{
return this.http.get(this.apiUrl + '/transactions');
}
+ login(username: string, password: string): Observable{
+ return this.http.post(this.apiUrl + '/auth/login',{ 'username': username, 'password': password});
+ }
}
diff --git a/server/src/index.ts b/server/src/index.ts
index bd396a8..c186e67 100644
--- a/server/src/index.ts
+++ b/server/src/index.ts
@@ -1,6 +1,7 @@
import express, { Express, Request, Response } from "express";
import cors from "cors";
import transactionsRouter from './routes/transactions';
+import authRouter from './routes/auth';
import { db, testConnection } from "./util/db";
import { logger } from "./util/logging";
@@ -13,6 +14,7 @@ app.get("/api/health", (req: Request, res: Response) => {
});
app.use('/api/transactions', transactionsRouter);
+app.use('/api/auth', authRouter);
const PORT: number = parseInt(process.env.PORT as string) || 3000;
diff --git a/server/src/routes/auth.ts b/server/src/routes/auth.ts
new file mode 100644
index 0000000..4212c57
--- /dev/null
+++ b/server/src/routes/auth.ts
@@ -0,0 +1,14 @@
+import express from 'express';
+
+const router = express.Router();
+
+router.post('/login', async (req, res) => {
+ try {
+ res.json('abc');
+ } catch (err) {
+ console.error('Failed to authenticate:', err);
+ res.status(500).json({ error: 'Failed to authenticate' });
+ }
+});
+
+export default router;