Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions firebaseConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import { getFirestore } from "https://www.gstatic.com/firebasejs/10.5.2/firebase
// appId: Application ID for the Firebase app, it is unique to this application

// STEP 1: Declare Firebase Environment Variables
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "YOUR-OWN-VARIABLE",
authDomain: "YOUR-OWN-VARIABLE",
projectId: "YOUR-OWN-VARIABLE",
storageBucket: "YOUR-OWN-VARIABLE",
messagingSenderId: "YOUR-OWN-VARIABLE",
appId: "YOUR-OWN-VARIABLE",
};
apiKey: "AIzaSyBziqda5Gv47CKTO3d7ShdcV3lP3M-ocFM",
authDomain: "learnfirebase-cf66d.firebaseapp.com",
projectId: "learnfirebase-cf66d",
storageBucket: "learnfirebase-cf66d.appspot.com",
messagingSenderId: "448075621583",
appId: "1:448075621583:web:79dfc732d37ded004603ba"
};

// initialze firebase in our project by passing in our environment variables to the `initializeApp` method
const app = initializeApp(firebaseConfig);
Expand Down
6 changes: 6 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,13 @@ function handleItemAdd() {
2) userEmail
3) todoItemText*/

storeToDoItem(userId, userEmail, todoItemText);

// clear the input value after storing the data
textInput.value = "";



/*
Fetch and display all items in the todo list.
Since the user just added a new item we must display it, and so we re-fetch all the items (documents)
Expand All @@ -156,6 +160,8 @@ function handleItemAdd() {
parameters:
1) userID
*/

fetchAndDisplayAllToDoItems(userId);
}

document.getElementById("new-todo-btn").addEventListener("click", handleItemAdd);
11 changes: 11 additions & 0 deletions utilities/authentication/SignInWithGoogle.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
import { signInWithPopup, GoogleAuthProvider } from "https://www.gstatic.com/firebasejs/10.5.2/firebase-auth.js";
import { auth } from "../../firebaseConfig.js";



// Function handles the users signin with their google account
export async function signInUserWithGoogle () {



/* STEP 2: Create a new instance of the Firebase Google Authenticator Proivider
We are going to look at the following documentation to figure out how we might do
this: https://firebase.google.com/docs/auth/web/google-signin */

const provider = new GoogleAuthProvider();



try {

/* STEP 3: Create a pop-up window to appear so users may enter there google emails to
complete the authetication process. We are going to look at the following documentation
to figure out how we might do this: https://firebase.google.com/docs/auth/web/google-signin */

await signInWithPopup(auth, provider);


// return the string "success" if sign-in was complete
return "success";

Expand Down
1 change: 1 addition & 0 deletions utilities/database/FetchAllToDoItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export async function fetchAllToDoItems(userId) {
/*STEP 8: Get a refernce to the collection we want to store. Lets use the following documentation
to figure this out: https://firebase.google.com/docs/firestore/query-data/get-data */

const userTodoListCollection = collection(db, `todo-list-${userId}`);
// get all the documents in the user specified collection
const querySnapshot = await getDocs(userTodoListCollection);

Expand Down
8 changes: 8 additions & 0 deletions utilities/database/StoreToDoItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@ export async function storeToDoItem(userId, userEmail, itemText) {
/*STEP 5: Get a refernce to the collection we want to store. Lets use the following documentation
to figure this out: https://firebase.google.com/docs/firestore/query-data/get-data */

const userTodoListCollection = collection(db, `todo-list-${userId}`);

// generate a unique id for the document and assemble our data into an object
const docUniqueId = generateUniqueId();

//STEP 6: Create a object called data that will hold the information going into the document

const data = {
userId: userId,
email: userEmail,
itemText: itemText,
uid: docUniqueId,

};

// store the following data in a document the specified user collection
// userTodoListCollection -> the collection we store into
Expand Down