├── scripts ├── index.js ├── firebase.js ├── signin.js ├── signup.js └── home.js ├── index.html ├── home.html ├── signin.html └── signup.html /scripts/index.js: -------------------------------------------------------------------------------- 1 | import { renderBlogs } from "./home.js"; 2 | renderBlogs(); -------------------------------------------------------------------------------- /scripts/firebase.js: -------------------------------------------------------------------------------- 1 | import { initializeApp } from "https://www.gstatic.com/firebasejs/10.13.0/firebase-app.js"; 2 | import { getAuth } from "https://www.gstatic.com/firebasejs/10.13.0/firebase-auth.js"; 3 | import { getFirestore } from "https://www.gstatic.com/firebasejs/10.13.0/firebase-firestore.js"; 4 | 5 | // My web app's Firebase configuration 6 | const firebaseConfig = { 7 | apiKey: "AIzaSyAu5yHHFVN6n8qk_mWJioo1btbrDBJl1Nw", 8 | authDomain: "blogging-site-c7224.firebaseapp.com", 9 | projectId: "blogging-site-c7224", 10 | storageBucket: "blogging-site-c7224.appspot.com", 11 | messagingSenderId: "288811689646", 12 | appId: "1:288811689646:web:e5fa5b9fb51f2760646f3f", 13 | measurementId: "G-GFZJRRT55C" 14 | }; 15 | 16 | // Initialize Firebase 17 | const app = initializeApp(firebaseConfig); 18 | export const auth = getAuth(app); 19 | export const db = getFirestore(app); -------------------------------------------------------------------------------- /scripts/signin.js: -------------------------------------------------------------------------------- 1 | import { signInWithEmailAndPassword } from 'https://www.gstatic.com/firebasejs/10.13.0/firebase-auth.js' 2 | import { auth } from './firebase.js' 3 | 4 | // For Getting User Details From HTML 5 | const signIn = document.querySelector("#sign-in"); 6 | const email = document.querySelector("#email"); 7 | const password = document.querySelector("#password"); 8 | 9 | // Functionality For Login 10 | signIn.addEventListener("submit", (event) => { 11 | event.preventDefault(); 12 | // Checking If User Enters a Details Or Not 13 | if (email.value && password.value) { 14 | signInWithEmailAndPassword(auth, email.value, password.value) 15 | .then((userCredential) => { 16 | // For Opening Index Page If Successfull Login 17 | window.open("home.html", "_self"); 18 | }) 19 | .catch((error) => { 20 | const errorCode = error.code; 21 | const errorMessage = error.message; 22 | alert(errorCode, errorMessage); 23 | }); 24 | 25 | // For Empty Input 26 | email.value = ""; 27 | password.value = ""; 28 | } else { 29 | // For User Not Enters Any Details 30 | my_modal_1.showModal(); 31 | } 32 | }) 33 | 34 | -------------------------------------------------------------------------------- /scripts/signup.js: -------------------------------------------------------------------------------- 1 | import { createUserWithEmailAndPassword } from 'https://www.gstatic.com/firebasejs/10.13.0/firebase-auth.js' 2 | import { auth } from './firebase.js' 3 | 4 | // For Getting User Details From HTML 5 | const signUpForm = document.querySelector("#signup-form"); 6 | const username = document.querySelector("#name"); 7 | const email = document.querySelector("#email"); 8 | const password = document.querySelector("#password"); 9 | 10 | // Functionality For Registration 11 | signUpForm.addEventListener("submit", (event) => { 12 | event.preventDefault(); 13 | // Checking If User Enters a Details Or Not 14 | if (email.value && password.value) { 15 | createUserWithEmailAndPassword(auth, email.value, password.value) 16 | .then((userCredential) => { 17 | const user = userCredential.user; 18 | console.log(user.uid); 19 | }) 20 | .catch((error) => { 21 | const errorCode = error.code; 22 | const errorMessage = error.message; 23 | alert(errorCode, errorMessage); 24 | }); 25 | 26 | // For Empty Input 27 | username.value = ""; 28 | email.value = ""; 29 | password.value = ""; 30 | 31 | // For Showing Popup Of Successfull Registration 32 | my_modal_2.showModal(); 33 | } else { 34 | // For User Not Enters Any Details 35 | my_modal_1.showModal(); 36 | } 37 | }) 38 | -------------------------------------------------------------------------------- /scripts/home.js: -------------------------------------------------------------------------------- 1 | import { signOut, onAuthStateChanged } from 'https://www.gstatic.com/firebasejs/9.22.2/firebase-auth.js'; 2 | import { collection, addDoc, query, orderBy, onSnapshot, deleteDoc, doc } from 'https://www.gstatic.com/firebasejs/10.13.0/firebase-firestore.js'; 3 | import { auth, db } from './firebase.js'; 4 | 5 | const blogsContainer = document.getElementById('blogsContainer'); 6 | 7 | export function renderBlogs(blogs) { 8 | blogsContainer.innerHTML = ''; 9 | blogs.forEach(blog => { 10 | const blogDiv = document.createElement('div'); 11 | blogDiv.className = 'bg-gray-50 p-4 rounded-lg shadow-md mb-5'; 12 | blogDiv.innerHTML = ` 13 |
${blog.body}
15 | ${blog.date.toDate().toLocaleString()} 16 |