diff --git a/assets/js/auth.js b/assets/js/auth.js new file mode 100644 index 0000000..a6ff430 --- /dev/null +++ b/assets/js/auth.js @@ -0,0 +1,105 @@ +import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.1/firebase-app.js"; +import { + getAuth, + createUserWithEmailAndPassword, + signInWithEmailAndPassword, + GoogleAuthProvider, + signInWithPopup, + onAuthStateChanged +} from "https://www.gstatic.com/firebasejs/9.6.1/firebase-auth.js"; + +// Your web app's Firebase configuration +const firebaseConfig = { + apiKey: "AIzaSyAuabZynwAn8r91_toMzdN2_vCVOwLsAf8", + authDomain: "ai-resume-builder-90135.firebaseapp.com", + projectId: "ai-resume-builder-90135", + storageBucket: "ai-resume-builder-90135.firebasestorage.app", + messagingSenderId: "465451014283", + appId: "1:465451014283:web:355ddebe12bc8a2dfedc8e", + measurementId: "G-4B91V0ZY58" +}; + +// Initialize Firebase +const app = initializeApp(firebaseConfig); +const auth = getAuth(app); +const provider = new GoogleAuthProvider(); + +// DOM Elements +const loginForm = document.getElementById('loginForm'); +const signupForm = document.getElementById('signupForm'); +const googleLoginBtn = document.getElementById('googleLoginBtn'); +const googleSignupBtn = document.getElementById('googleSignupBtn'); +const errorContainer = document.getElementById('errorContainer'); + +// Function to display errors +const showError = (message) => { + errorContainer.textContent = message; + errorContainer.style.display = 'block'; +}; + +// Redirect if user is already logged in +onAuthStateChanged(auth, (user) => { + if (user) { + window.location.href = 'home.php'; + } +}); + +// Email/Password Sign Up +if (signupForm) { + signupForm.addEventListener('submit', (e) => { + e.preventDefault(); + const email = signupForm.querySelector('#signupEmail').value; + const password = signupForm.querySelector('#signupPassword').value; + + createUserWithEmailAndPassword(auth, email, password) + .then((userCredential) => { + // Signed in + window.location.href = 'home.php'; + }) + .catch((error) => { + showError(error.message); + }); + }); +} + +// Email/Password Login +if (loginForm) { + loginForm.addEventListener('submit', (e) => { + e.preventDefault(); + const email = loginForm.querySelector('#loginEmail').value; + const password = loginForm.querySelector('#loginPassword').value; + + signInWithEmailAndPassword(auth, email, password) + .then((userCredential) => { + // Signed in + window.location.href = 'home.php'; + }) + .catch((error) => { + showError(error.message); + }); + }); +} + +// Google Sign-In +const handleGoogleSignIn = (e) => { + e.preventDefault(); + signInWithPopup(auth, provider) + .then((result) => { + // This gives you a Google Access Token. You can use it to access the Google API. + const credential = GoogleAuthProvider.credentialFromResult(result); + const token = credential.accessToken; + // The signed-in user info. + const user = result.user; + window.location.href = 'home.php'; + }).catch((error) => { + // Handle Errors here. + showError(error.message); + }); +}; + +if (googleLoginBtn) { + googleLoginBtn.addEventListener('click', handleGoogleSignIn); +} +if (googleSignupBtn) { + googleSignupBtn.addEventListener('click', handleGoogleSignIn); +} diff --git a/home.php b/home.php new file mode 100644 index 0000000..808e8be --- /dev/null +++ b/home.php @@ -0,0 +1,55 @@ + + + + + + Home - AI Resume Builder + + + + +
+

Welcome to the AI Resume Builder

+

You are logged in. Template selection coming soon!

+ +
+ + + + diff --git a/index.php b/index.php index 5fe369b..fe176a4 100644 --- a/index.php +++ b/index.php @@ -39,11 +39,14 @@ + + +
-
+
@@ -55,7 +58,7 @@
or
-
or
-
+ \ No newline at end of file