-
Notifications
You must be signed in to change notification settings - Fork 0
/
authService.ts
33 lines (30 loc) · 1.2 KB
/
authService.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { auth } from './firebaseConfig';
import { createUserWithEmailAndPassword, signInWithEmailAndPassword,
sendPasswordResetEmail, UserCredential } from 'firebase/auth';
export const register = async (email: string, password: string): Promise<UserCredential | void> => {
try {
console.log('authService.ts');
const userCredential: UserCredential = await createUserWithEmailAndPassword(auth, email, password);
console.log('User registered:', userCredential.user);
return userCredential;
} catch (error) {
console.error('Error registering user:', error);
}
};
export const login = async (email: string, password: string): Promise<UserCredential | void> => {
try {
const userCredential: UserCredential = await signInWithEmailAndPassword(auth, email, password);
console.log('User logged in:', userCredential.user);
return userCredential;
} catch (error) {
console.error('Error logging in:', error);
}
};
export const resetPassword = async (email: string): Promise<void> => {
try {
await sendPasswordResetEmail(auth, email);
console.log('Password reset email sent to:', email);
} catch (error) {
console.error('Error sending password reset email:', error);
}
};