auth frontend
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -192,4 +192,4 @@ dist
|
||||
.ionide
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/nextjs,node,visualstudiocode
|
||||
|
||||
.docker/
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<form [formGroup]="loginForm" (ngSubmit)="onSubmit()" novalidate>
|
||||
<!-- Email -->
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">Email</label>
|
||||
<label for="email" class="form-label">Username</label>
|
||||
<input
|
||||
type="text"
|
||||
id="username"
|
||||
@@ -49,9 +49,7 @@
|
||||
class="btn btn-primary w-100 mb-3"
|
||||
>
|
||||
@if (loading) {
|
||||
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true">
|
||||
Signing In...
|
||||
</span>
|
||||
<span> Signing In... </span>
|
||||
}@else {
|
||||
<span>Sign In</span>
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
});
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,4 +14,7 @@ export class APIService {
|
||||
getTransactions(): Observable<Transaction[]>{
|
||||
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 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;
|
||||
|
||||
|
||||
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