auth frontend
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -192,4 +192,4 @@ dist
|
|||||||
.ionide
|
.ionide
|
||||||
|
|
||||||
# End of https://www.toptal.com/developers/gitignore/api/nextjs,node,visualstudiocode
|
# End of https://www.toptal.com/developers/gitignore/api/nextjs,node,visualstudiocode
|
||||||
|
.docker/
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<form [formGroup]="loginForm" (ngSubmit)="onSubmit()" novalidate>
|
<form [formGroup]="loginForm" (ngSubmit)="onSubmit()" novalidate>
|
||||||
<!-- Email -->
|
<!-- Email -->
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="email" class="form-label">Email</label>
|
<label for="email" class="form-label">Username</label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
id="username"
|
id="username"
|
||||||
@@ -49,9 +49,7 @@
|
|||||||
class="btn btn-primary w-100 mb-3"
|
class="btn btn-primary w-100 mb-3"
|
||||||
>
|
>
|
||||||
@if (loading) {
|
@if (loading) {
|
||||||
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true">
|
<span> Signing In... </span>
|
||||||
Signing In...
|
|
||||||
</span>
|
|
||||||
}@else {
|
}@else {
|
||||||
<span>Sign In</span>
|
<span>Sign In</span>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { Component } from '@angular/core';
|
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 { Router } from '@angular/router';
|
||||||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||||
|
import { APIService } from '../../services/api';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-screen-login',
|
selector: 'app-screen-login',
|
||||||
@@ -18,38 +19,30 @@ export class ScreenLogin {
|
|||||||
error: string | null = null;
|
error: string | null = null;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
private api: APIService,
|
||||||
|
private router: Router,
|
||||||
private fb: FormBuilder,
|
private fb: FormBuilder,
|
||||||
private router: Router
|
|
||||||
) {
|
) {
|
||||||
this.loginForm = this.fb.group({
|
this.loginForm = this.fb.group({
|
||||||
email: ['', [Validators.required, Validators.email]],
|
username: ['', [Validators.required]],
|
||||||
password: ['', [Validators.required, Validators.minLength(6)]],
|
password: ['', [Validators.required]],
|
||||||
rememberMe: [false]
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
this.submitted = true;
|
this.submitted = true;
|
||||||
this.error = null;
|
this.error = null;
|
||||||
|
|
||||||
if (this.loginForm.invalid) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
const { email, password, rememberMe } = this.loginForm.value;
|
|
||||||
|
|
||||||
/*
|
this.api.login(this.loginForm.value.username, this.loginForm.value.password).subscribe({
|
||||||
this.authService.login(email, password, rememberMe).subscribe({
|
|
||||||
next: () => {
|
next: () => {
|
||||||
this.router.navigate(['/dashboard']); // Redirect after login
|
//this.router.navigate(['']);
|
||||||
},
|
},
|
||||||
error: (err) => {
|
error: (err) => {
|
||||||
this.error = err.error?.message || 'Login failed. Please try again.';
|
this.error = err.error?.message || 'Login failed. Please try again.';
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,4 +14,7 @@ export class APIService {
|
|||||||
getTransactions(): Observable<Transaction[]>{
|
getTransactions(): Observable<Transaction[]>{
|
||||||
return this.http.get<Transaction[]>(this.apiUrl + '/transactions');
|
return this.http.get<Transaction[]>(this.apiUrl + '/transactions');
|
||||||
}
|
}
|
||||||
|
login(username: string, password: string): Observable<any>{
|
||||||
|
return this.http.post(this.apiUrl + '/auth/login',{ 'username': username, 'password': password});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import express, { Express, Request, Response } from "express";
|
import express, { Express, Request, Response } from "express";
|
||||||
import cors from "cors";
|
import cors from "cors";
|
||||||
import transactionsRouter from './routes/transactions';
|
import transactionsRouter from './routes/transactions';
|
||||||
|
import authRouter from './routes/auth';
|
||||||
import { db, testConnection } from "./util/db";
|
import { db, testConnection } from "./util/db";
|
||||||
import { logger } from "./util/logging";
|
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/transactions', transactionsRouter);
|
||||||
|
app.use('/api/auth', authRouter);
|
||||||
|
|
||||||
const PORT: number = parseInt(process.env.PORT as string) || 3000;
|
const PORT: number = parseInt(process.env.PORT as string) || 3000;
|
||||||
|
|
||||||
|
|||||||
14
server/src/routes/auth.ts
Normal file
14
server/src/routes/auth.ts
Normal file
@@ -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;
|
||||||
Reference in New Issue
Block a user