-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirebase1.html
49 lines (43 loc) · 1.9 KB
/
firebase1.html
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
<script src="https://www.gstatic.com/firebasejs/7.21.0/firebase.js"></script>
<script>
firebaseConfig() {
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: "AIzaSyAol_fATQ8OuBQRALAo_o7pFSE_01-_W3g",
authDomain: "e-commerce-social-media-webapp.firebaseapp.com",
projectId: "e-commerce-social-media-webapp",
storageBucket: "e-commerce-social-media-webapp.appspot.com",
messagingSenderId: "894487759666",
appId: "1:894487759666:web:806b8c0b904b954a4a252b",
measurementId: "G-18THWBJCKC"
};
}
firebase.initializeApp(firebaseConfig);
// Save signup data to Firebase Realtime Database
const signupData = {
username: 'username',
email: '[email protected]',
password: 'password',
};
firebase.database().ref('users').child(signupData.username).set(signupData);
// Save profile image to Firebase Storage
const profileImage = document.getElementById('profile-image');
const profileImageUrl = await profileImage.files[0].upload('profile-images');
firebase.database().ref('users').child(signupData.username).child('profileImageUrl').set(profileImageUrl);
// Redirect the user to the dashboard page if the login is successful
const loginButton = document.getElementById('login-button');
loginButton.addEventListener('click', () => {
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
firebase.auth().signInWithEmailAndPassword(username, password).then((user) => {
window.location.href = 'dashboard.html';
}, (error) => {
alert(error.message);
});
});
</script>
<!--The code you provided is a good start for a Firebase-powered e-commerce social media web app. It includes the following functionality:
Saving signup data to Firebase Realtime Database
Saving profile image to Firebase Storage
Redirecting the user to the dashboard page if the login is successful
-->