2024-03-19 09:39:37 -07:00
|
|
|
import { Component } from '@angular/core';
|
2024-03-20 11:37:59 -07:00
|
|
|
import { AngularFireAuth } from '@angular/fire/compat/auth';
|
|
|
|
|
import { Router } from '@angular/router';
|
2024-03-19 09:39:37 -07:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'ngx-register',
|
|
|
|
|
templateUrl: './register.component.html',
|
|
|
|
|
})
|
2024-03-20 11:37:59 -07:00
|
|
|
export class NgxRegisterComponent {
|
|
|
|
|
user = {
|
|
|
|
|
fullName: '',
|
|
|
|
|
email: '',
|
|
|
|
|
password: '',
|
|
|
|
|
confirmPassword: ''
|
|
|
|
|
};
|
|
|
|
|
submitted = false;
|
|
|
|
|
errors: string[] = [];
|
|
|
|
|
|
|
|
|
|
constructor(private fireAuth: AngularFireAuth, private router: Router) {}
|
|
|
|
|
|
|
|
|
|
async register() {
|
|
|
|
|
this.submitted = true;
|
|
|
|
|
try {
|
|
|
|
|
if (this.user.password !== this.user.confirmPassword) {
|
|
|
|
|
throw new Error('Password does not match the confirm password.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await this.fireAuth.createUserWithEmailAndPassword(this.user.email, this.user.password);
|
|
|
|
|
// Registration successful, redirect to login page or dashboard
|
|
|
|
|
this.router.navigate(['auth/login']);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
// Handle registration errors
|
|
|
|
|
console.error('Error registering user:', error);
|
|
|
|
|
this.errors.push(error.message || 'An error occurred. Please try again later.');
|
|
|
|
|
}
|
|
|
|
|
this.submitted = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getConfigValue(key: string): any {
|
|
|
|
|
// Implement this method based on your configuration retrieval logic
|
|
|
|
|
}
|
|
|
|
|
}
|