├── src ├── main.css ├── app │ ├── logout.js │ ├── loginCheck.js │ ├── firebase.js │ ├── postList.js │ ├── showMessage.js │ ├── githubLogin.js │ ├── facebookLogin.js │ ├── googleLogin.js │ ├── signinForm.js │ └── signupForm.js ├── main.js ├── 404.html └── index.html ├── firestore.indexes.json ├── .firebaserc ├── firebase.json ├── firestore.rules ├── README.md ├── package.json └── .gitignore /src/main.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: #202020; 3 | color: white; 4 | } -------------------------------------------------------------------------------- /firestore.indexes.json: -------------------------------------------------------------------------------- 1 | { 2 | "indexes": [], 3 | "fieldOverrides": [] 4 | } 5 | -------------------------------------------------------------------------------- /.firebaserc: -------------------------------------------------------------------------------- 1 | { 2 | "projects": { 3 | "default": "fir-app-ea974" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /firebase.json: -------------------------------------------------------------------------------- 1 | { 2 | "firestore": { 3 | "rules": "firestore.rules", 4 | "indexes": "firestore.indexes.json" 5 | }, 6 | "hosting": { 7 | "public": "src", 8 | "ignore": [ 9 | "firebase.json", 10 | "**/.*", 11 | "**/node_modules/**" 12 | ] 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /firestore.rules: -------------------------------------------------------------------------------- 1 | rules_version = '2'; 2 | service cloud.firestore { 3 | match /databases/{database}/documents { 4 | match /posts/{postId} { 5 | allow read, write: if request.auth.uid != null; 6 | // allow write: if request.token.admin == true; 7 | } 8 | 9 | match /tasks/{taskId} { 10 | allow read, write: if true == true; 11 | } 12 | 13 | } 14 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Firebase Javacript Authentication 2 | 3 | ### Installation 4 | 5 | ```sh 6 | git clone https://github.com/FaztWeb/firebase-auth-example 7 | cd firebase-auth-example 8 | npm i 9 | ``` 10 | 11 | go to `src/app/firebase.js` and replace this with your firebase credentials: 12 | 13 | ```js 14 | const firebaseConfig = { 15 | // Paste your firebase config here 16 | }; 17 | ``` 18 | 19 | ``` 20 | firebase serve 21 | ``` -------------------------------------------------------------------------------- /src/app/logout.js: -------------------------------------------------------------------------------- 1 | import { signOut } from "https://www.gstatic.com/firebasejs/9.10.0/firebase-auth.js" 2 | import { auth } from "./firebase.js"; 3 | 4 | const logout = document.querySelector("#logout"); 5 | 6 | logout.addEventListener("click", async (e) => { 7 | e.preventDefault(); 8 | try { 9 | await signOut(auth) 10 | console.log("signup out"); 11 | } catch (error) { 12 | console.log(error) 13 | } 14 | }); -------------------------------------------------------------------------------- /src/app/loginCheck.js: -------------------------------------------------------------------------------- 1 | const loggedOutLinks = document.querySelectorAll(".logged-out"); 2 | const loggedInLinks = document.querySelectorAll(".logged-in"); 3 | 4 | export const loginCheck = (user) => { 5 | if (user) { 6 | loggedInLinks.forEach((link) => (link.style.display = "block")); 7 | loggedOutLinks.forEach((link) => (link.style.display = "none")); 8 | } else { 9 | loggedInLinks.forEach((link) => (link.style.display = "none")); 10 | loggedOutLinks.forEach((link) => (link.style.display = "block")); 11 | } 12 | }; -------------------------------------------------------------------------------- /src/app/firebase.js: -------------------------------------------------------------------------------- 1 | import { initializeApp } from "https://www.gstatic.com/firebasejs/9.10.0/firebase-app.js"; 2 | import { getAuth } from "https://www.gstatic.com/firebasejs/9.10.0/firebase-auth.js" 3 | import { getFirestore } from "https://www.gstatic.com/firebasejs/9.10.0/firebase-firestore.js" 4 | 5 | const firebaseConfig = { 6 | // Paste your firebase config here 7 | }; 8 | 9 | // Initialize Firebase 10 | export const app = initializeApp(firebaseConfig); 11 | export const auth = getAuth(app) 12 | export const db = getFirestore(app) -------------------------------------------------------------------------------- /src/app/postList.js: -------------------------------------------------------------------------------- 1 | const postList = document.querySelector(".posts"); 2 | 3 | export const setupPosts = (data) => { 4 | if (data.length) { 5 | let html = ""; 6 | data.forEach((doc) => { 7 | const post = doc.data(); 8 | const li = ` 9 |
${post.content}
12 |The specified file was not found on this website. Please check the URL for mistakes and try again.
29 |This page was generated by the Firebase Command-Line Interface. To modify it, edit the 404.html file in your project's configured public directory.