31 lines
744 B
TypeScript
31 lines
744 B
TypeScript
import {Injectable} from '@angular/core';
|
|
import {Router} from '@angular/router';
|
|
import {AngularFireAuth} from '@angular/fire/compat/auth';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class AuthService {
|
|
|
|
constructor(private fireAuth: AngularFireAuth,
|
|
private router: Router) {
|
|
}
|
|
|
|
public login(email: string, password: string, redirectUrl: string) {
|
|
this.fireAuth.signInWithEmailAndPassword(email, password)
|
|
.then(() => {
|
|
this.router.navigateByUrl(redirectUrl);
|
|
})
|
|
.catch((error) => {
|
|
console.error(error.message());
|
|
});
|
|
}
|
|
|
|
public logout(redirectUrl: string) {
|
|
this.fireAuth.signOut()
|
|
.then(() => {
|
|
this.router.navigateByUrl(redirectUrl);
|
|
});
|
|
}
|
|
}
|