-
Notifications
You must be signed in to change notification settings - Fork 2
/
firebaseAuth.js
60 lines (53 loc) · 2.25 KB
/
firebaseAuth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { initializeApp } from 'https://www.gstatic.com/firebasejs/10.4.0/firebase-app.js'
import {
getAuth,
signInWithEmailAndPassword,
} from 'https://www.gstatic.com/firebasejs/10.4.0/firebase-auth.js'
import { getFirestore } from 'https://www.gstatic.com/firebasejs/10.4.0/firebase-firestore.js'
// Your web app's Firebase configuration
import firebaseConfig from './firebaseConfig.js'
// Initialize Firebase
const app = initializeApp(firebaseConfig)
const auth = getAuth(app)
const db = getFirestore(app)
// Reference the login form
const loginForm = document.getElementById('adminlogin-form')
// Add an event listener to the form for login
loginForm.addEventListener('submit', async (e) => {
e.preventDefault() // Prevent the default form submission
// Get user inputs
const email = document.getElementById('email').value
const password = document.getElementById('password').value
try {
// Sign in with email and password
const userCredential = await signInWithEmailAndPassword(
auth,
email,
password
)
// User signed in successfully
const user = userCredential.user
console.log('User signed in:', user)
document.getElementById('pop3').style.display = 'none'
document.getElementById('feedback-cont2').style.display = 'none'
//None
document.getElementById('slideid').style.display = 'none'
document.getElementById('quizform').style.display = 'none'
document.getElementById('result-container').style.display = 'none'
document.getElementById('add-form').style.display = 'none'
document.getElementById('question-container').style.display = 'none'
document.getElementById('addlangform').style.display = 'none'
document.getElementById('results-container').style.display = 'none'
//Display
document.getElementById('filterdata').style.display = 'block'
} catch (error) {
const feedbackContainer = document.getElementById('feedback-cont2')
feedbackContainer.textContent = 'Worng credentials'
feedbackContainer.classList.add('feedback2', 'error')
feedbackContainer.style.display = 'block'
// Handle errors (e.g., wrong email or password)
const errorCode = error.code
const errorMessage = error.message
console.error('Login error:', errorCode, errorMessage)
}
})