From 111d1a7b48f73ad344036570f441e5af5d229bc4 Mon Sep 17 00:00:00 2001 From: eneller Date: Sat, 7 Mar 2026 13:53:46 +0100 Subject: [PATCH] auth frontend --- .gitignore | 2 +- .../screens/screen-login/screen-login.html | 6 ++--- .../app/screens/screen-login/screen-login.ts | 23 +++++++------------ client/src/app/services/api.ts | 3 +++ server/src/index.ts | 2 ++ server/src/routes/auth.ts | 14 +++++++++++ 6 files changed, 30 insertions(+), 20 deletions(-) create mode 100644 server/src/routes/auth.ts diff --git a/.gitignore b/.gitignore index 549a6a8..e291472 100644 --- a/.gitignore +++ b/.gitignore @@ -192,4 +192,4 @@ dist .ionide # End of https://www.toptal.com/developers/gitignore/api/nextjs,node,visualstudiocode - +.docker/ diff --git a/client/src/app/screens/screen-login/screen-login.html b/client/src/app/screens/screen-login/screen-login.html index 4185b12..c9462d1 100644 --- a/client/src/app/screens/screen-login/screen-login.html +++ b/client/src/app/screens/screen-login/screen-login.html @@ -12,7 +12,7 @@
- + @if (loading) { - + 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;