-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgetMyProfile.js
More file actions
38 lines (31 loc) · 859 Bytes
/
getMyProfile.js
File metadata and controls
38 lines (31 loc) · 859 Bytes
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
import { https, logger } from 'firebase-functions/v2';
import { getFirestore } from 'firebase-admin/firestore';
import { safelyInitializeApp } from '../firebase.js';
safelyInitializeApp();
const db = getFirestore();
export const myProfile = async (auth) => {
let profile = {
displayName: auth.token.displayName,
email: auth.token.email,
license: '',
seal: '',
};
try {
const snapshot = await db.collection('submitters').doc(auth.uid).get();
profile = snapshot.data();
} catch (error) {
logger.error('error querying profile', error, auth, {
structuredData: true,
});
}
if (!profile) {
logger.warn('profile is empty', profile, {
structuredData: true,
});
throw new https.HttpsError(
'failed-precondition',
'profile has not been written yet',
);
}
return profile;
};