I am using firebase a backend just to store the list of emails. So the only product I am using of firebase is firestore.
Every firebase project has some config data associated with it. This is essentially like a password that allows you to access the backend. I have stored this data in a file called firebase-config.js. This file is not on version control (github) as I has secret data. Here's the code inside it:
import*asfirebasefrom"firebase/app";import"firebase/firestore";constfirebaseConfig={// Secret Credentials from Firebase};exportdefaultfirebase.initializeApp(firebaseConfig);
This file export the firebase object which is imported by src/components/MailBox/index.js. This is used to perform write operations to the database.
// line 4importfirebasefrom"../../firebase-config";// line 15 in MailBox Componentsubscribe=()=>{constmail=this.state.mail;if(!this.validateEmail(mail))return;constdb=firebase.firestore();db.collection("emails").add({mail:this.state.mail,source:"sahil.surge.sh"});this.setState({subscribed:true});};
Note that people usually go with using something like MailChimp to manage mailing list. I've gone this way just so that I can personally mail and communicate with people
Can you help me understand how does this firebase thing works when you are adding a new subscriber to your mailer?
Yea Sure!
I am using firebase a backend just to store the list of emails. So the only product I am using of firebase is firestore.
Every firebase project has some config data associated with it. This is essentially like a password that allows you to access the backend. I have stored this data in a file called
firebase-config.js
. This file is not on version control (github) as I has secret data. Here's the code inside it:This file export the
firebase
object which is imported bysrc/components/MailBox/index.js
. This is used to perform write operations to the database.You can read more in the firebase documentation:
Hope I cleared your doubts.
Thanks man! This was really helpful. :)
By the way, I really liked the concept of personally mailing and building real network. Glad I found your blog.
😄