adding bunch of stuff for user getting
This commit is contained in:
@@ -11,8 +11,11 @@
|
||||
|
||||
|
||||
// Import the functions you need from the SDKs you need
|
||||
import { initializeApp } from "firebase/app";
|
||||
import * as firebase from 'firebase/app';
|
||||
import { getAnalytics } from "firebase/analytics";
|
||||
import { getFirestore } from "firebase/firestore";
|
||||
import { browserSessionPersistence, getAuth, setPersistence } from 'firebase/auth';
|
||||
|
||||
// TODO: Add SDKs for Firebase products that you want to use
|
||||
// https://firebase.google.com/docs/web/setup#available-libraries
|
||||
|
||||
@@ -29,5 +32,10 @@ const firebaseConfig = {
|
||||
};
|
||||
|
||||
// Initialize Firebase
|
||||
const app = initializeApp(firebaseConfig);
|
||||
const analytics = getAnalytics(app);
|
||||
const app = firebase.initializeApp(firebaseConfig);
|
||||
const analytics = getAnalytics(app);
|
||||
|
||||
console.log('initialized firebase')
|
||||
|
||||
setPersistence(getAuth(), browserSessionPersistence)
|
||||
|
||||
|
||||
@@ -1,5 +1,37 @@
|
||||
class UserService {
|
||||
|
||||
}
|
||||
import { User as FirUser } from "firebase/auth";
|
||||
import { Firestore, getFirestore, doc, getDoc } from "firebase/firestore";
|
||||
import { User } from '../models/user'
|
||||
|
||||
export {}
|
||||
export default class UserService {
|
||||
private db : Firestore = getFirestore()
|
||||
private static collectionName: string = "users"
|
||||
|
||||
constructor() {
|
||||
|
||||
}
|
||||
|
||||
// give back the avatar based on the person's google account avatar or if they set one then
|
||||
getUserAvatar(firstName: string, lastName: string, avatar: string = null) {
|
||||
if (avatar) {
|
||||
return avatar
|
||||
}
|
||||
|
||||
return `https://ui-avatars.com/api/?name=${firstName}+${lastName}`
|
||||
}
|
||||
|
||||
async getUser(userId: string) : Promise<User | null> {
|
||||
const docRef = doc(this.db, UserService.collectionName, userId);
|
||||
const docSnap = await getDoc(docRef);
|
||||
|
||||
if (docSnap.exists()) {
|
||||
console.log("Document data:", docSnap.data());
|
||||
let user: User = docSnap.data() as User
|
||||
return user
|
||||
} else {
|
||||
// doc.data() will be undefined in this case
|
||||
console.log("user not found!");
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user