-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (42 loc) · 1.11 KB
/
index.js
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const admin = require('firebase-admin')
class OriAuth {
constructor(config) {
admin.initializeApp({
credential: admin.credential.cert(config),
databaseURL: config.databaseURL,
});
}
async login(email, password) {
try {
await admin.auth().signInWithEmailAndPassword(email, password);
return 'Login successful';
} catch (error) {
throw new Error('Login failed');
}
}
async createUser(email, password, username) {
try {
const userCredential = await admin.auth().createUser({
email: email,
password: password,
});
const uid = userCredential.uid;
await admin.firestore().collection('users').doc(uid).set({
email: email,
username: username,
});
return 'User created successfully';
} catch (error) {
throw new Error('User creation failed');
}
}
async logout() {
await admin.auth().signOut();
return 'User logged out';
}
async resetPassword(email) {
await admin.auth().sendPasswordResetEmail(email);
return 'Password reset email sent';
}
}
module.exports = OriAuth;