Explorer
project
assets
index.css
index.html
index.js
Dependencies
firebase@10.1.0
Bootcamp
Study group
Collaborate with peers in your dedicated #study-group channel.
Code reviews
Submit projects for review using the /review
command in your #code-reviews channel
/* === Imports === */
import { initializeApp } from "firebase/app"
import { getAuth } from "firebase/auth"
/* === Firebase Setup === */
/* IMPORTANT: Replace this with your own firebaseConfig when doing challenges */
const firebaseConfig = {
apiKey: "AIzaSyBM1JtWaj4B_RyDqfnl9yqULGf3U0L33Sk",
authDomain: "moody-8f7be.firebaseapp.com",
projectId: "moody-8f7be",
storageBucket: "moody-8f7be.appspot.com"
}
const app = initializeApp(firebaseConfig)
const auth = getAuth(app)
/* === UI === */
/* == UI - Elements == */
const viewLoggedOut = document.getElementById("logged-out-view")
const viewLoggedIn = document.getElementById("logged-in-view")
const signInWithGoogleButtonEl = document.getElementById("sign-in-with-google-btn")
const emailInputEl = document.getElementById("email-input")
const passwordInputEl = document.getElementById("password-input")
const signInButtonEl = document.getElementById("sign-in-btn")
const createAccountButtonEl = document.getElementById("create-account-btn")
/* == UI - Event Listeners == */
signInWithGoogleButtonEl.addEventListener("click", authSignInWithGoogle)
signInButtonEl.addEventListener("click", authSignInWithEmail)
createAccountButtonEl.addEventListener("click", authCreateAccountWithEmail)
/* === Main Code === */
showLoggedOutView()
/* === Functions === */
/* = Functions - Firebase - Authentication = */
function authSignInWithGoogle() {
console.log("Sign in with Google")
}
function authSignInWithEmail() {
console.log("Sign in with email and password")
}
function authCreateAccountWithEmail() {
/* Challenge:
Import the createUserWithEmailAndPassword function from 'firebase/auth'
Use the code from the documentaion to make this function work.
Make sure to first create two consts, 'email' and 'password', to fetch the values from the input fields emailInputEl and passwordInputEl.
If the creation of user is successful then you should show the logged in view using showLoggedInView()
If something went wrong, then you should log the error message using console.error.
*/
}
/* == Functions - UI Functions == */
function showLoggedOutView() {
hideElement(viewLoggedIn)
showElement(viewLoggedOut)
}
function showLoggedInView() {
hideElement(viewLoggedOut)
showElement(viewLoggedIn)
}
function showElement(element) {
element.style.display = "flex"
}
function hideElement(element) {
element.style.display = "none"
}