Skip to content

Commit

Permalink
Merge pull request #11 from AnthonyDeSantiago/login_auth
Browse files Browse the repository at this point in the history
First round of auth building for sign in page
  • Loading branch information
camillereaves authored Sep 24, 2023
2 parents 11e1be9 + 49a05e5 commit 59776b7
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
5 changes: 3 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css" class="rel">
<script defer src = "sprout.js"></script>
<script defer src = "sprout.js" type = "module"></script>
<script defer src = "signin.js" type = "module"></script>
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.4.0/firebase-app.js";
Expand Down Expand Up @@ -63,4 +64,4 @@


</body>
</html>
</html>
70 changes: 70 additions & 0 deletions public/signin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.1.1/firebase-app.js";
import { getFirestore } from "https://www.gstatic.com/firebasejs/9.1.1/firebase-firestore.js"
import { collection, doc, getDoc, getDocs, addDoc, setDoc, Timestamp, serverTimestamp } from "https://www.gstatic.com/firebasejs/9.1.1/firebase-firestore.js"
import { query, orderBy, limit, where, onSnapshot } from "https://www.gstatic.com/firebasejs/9.1.1/firebase-firestore.js"
import { getAuth, createUserWithEmailAndPassword, signInWithEmailAndPassword, onAuthStateChanged } from "https://www.gstatic.com/firebasejs/9.1.1/firebase-auth.js"

const firebaseConfig = {
apiKey: "AIzaSyDA5itOehOkeLc9ob3a8GsTJ9VhbWdee7I",
authDomain: "sprout-financials.firebaseapp.com",
databaseURL: "https://sprout-financials-default-rtdb.firebaseio.com",
projectId: "sprout-financials",
storageBucket: "sprout-financials.appspot.com",
messagingSenderId: "864423850272",
appId: "1:864423850272:web:725227e1ed9a578ef36745",
measurementId: "G-Z0E9H5Z16M"
};
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
const users = collection(db, 'users')

const auth = getAuth();

console.log("signin.js loaded")

document.getElementById("login_form").addEventListener("submit", async function (e) {
e.preventDefault();

//var username = document.getElementById("username").value;
var email = document.getElementById("username").value;
var password = document.getElementById("password").value;

//const docRef = doc(db, 'users', username.toString());
//const userPage = await(getDoc(docRef));

signInWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
// Signed in
const user = userCredential.user;
console.log("user signed in");
// ...
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
});
});

onAuthStateChanged(auth, (user) => {
if (user) {
// User is signed in, see docs for a list of available properties
// https://firebase.google.com/docs/reference/js/auth.user
const uid = user.uid;
console.log(uid);
// ...
} else {
// User is signed out
// ...
}
});

/*
const user = auth.currentUser;
if (user) {
console.log("User is signed in"); //, see docs for a list of available properties
// https://firebase.google.com/docs/reference/js/auth.user
// ...
} else {
console.log("No user is signed in");
}*/

0 comments on commit 59776b7

Please sign in to comment.