feat(login): add login functionality with form validation
This commit is contained in:
parent
a54069f160
commit
89083f832f
7 changed files with 569 additions and 9 deletions
|
@ -1,11 +1,38 @@
|
|||
import { Component } from '@angular/core';
|
||||
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
|
||||
import PocketBase from 'pocketbase';
|
||||
import { environment } from '../../environments/environment.development';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-login',
|
||||
imports: [],
|
||||
imports: [ReactiveFormsModule],
|
||||
templateUrl: './login.component.html',
|
||||
styleUrl: './login.component.css'
|
||||
})
|
||||
export class LoginComponent {
|
||||
public loginForm!: FormGroup;
|
||||
public invalidCredentials = false;
|
||||
|
||||
constructor(private router: Router) { };
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loginForm = new FormGroup({
|
||||
email: new FormControl(''),
|
||||
password: new FormControl(''),
|
||||
});
|
||||
}
|
||||
|
||||
submit() {
|
||||
const pb = new PocketBase(environment.POCKETBASE);
|
||||
|
||||
pb.collection("users").authWithPassword(
|
||||
this.loginForm.get('email')?.value,
|
||||
this.loginForm.get('password')?.value
|
||||
).then(response => {
|
||||
this.invalidCredentials = false;
|
||||
}).catch(() => {
|
||||
this.invalidCredentials = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue