File tree 2 files changed +45
-0
lines changed
2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 30
30
}
31
31
</ style >
32
32
< footer >
33
+ < button id ="logoutBtn "> Logout</ button >
34
+ < script >
35
+ document . getElementById ( 'logoutBtn' ) . addEventListener ( 'click' , ( ) => {
36
+ firebase . auth ( ) . signOut ( ) . then ( ( ) => {
37
+ console . log ( 'User logged out' ) ;
38
+ } ) . catch ( ( error ) => {
39
+ console . error ( 'Error logging out:' , error ) ;
40
+ } ) ;
41
+ } ) ;
42
+ </ script >
43
+ < script >
44
+ function protegerRuta ( ) {
45
+ firebase . auth ( ) . onAuthStateChanged ( ( user ) => {
46
+ if ( ! user ) {
47
+ // Redireccionar a la página de inicio de sesión si no está autenticado
48
+ window . location . href = 'login.html' ;
49
+ }
50
+ } ) ;
51
+ }
52
+
53
+ // Llamar a la función de protección de ruta en las páginas que necesiten protección
54
+ protegerRuta ( ) ;
55
+ </ script >
33
56
< div class ="footer-imagenes ">
34
57
< a href ="https://instagram.com/grouvex " target ="_blank "> < img src ="https://grouvex.github.io/img/Instagram.png " alt =""> </ a >
35
58
< a href ="https://youtube.com/@Grouvex " target ="_blank "> < img src ="https://grouvex.github.io/img/YouTube.png " alt =""> </ a >
Original file line number Diff line number Diff line change
1
+ < form id ="loginForm ">
2
+ < input type ="email " id ="loginEmail " placeholder ="Email " required >
3
+ < input type ="password " id ="loginPassword " placeholder ="Password " required >
4
+ < button type ="submit "> Login</ button >
5
+ </ form >
6
+ < a src ="# "> #</ a >
7
+ < script >
8
+ document . getElementById ( 'loginForm' ) . addEventListener ( 'submit' , ( e ) => {
9
+ e . preventDefault ( ) ;
10
+ const email = document . getElementById ( 'loginEmail' ) . value ;
11
+ const password = document . getElementById ( 'loginPassword' ) . value ;
12
+
13
+ firebase . auth ( ) . signInWithEmailAndPassword ( email , password )
14
+ . then ( ( userCredential ) => {
15
+ // Usuario inició sesión
16
+ console . log ( 'User logged in:' , userCredential . user ) ;
17
+ } )
18
+ . catch ( ( error ) => {
19
+ console . error ( 'Error logging in user:' , error ) ;
20
+ } ) ;
21
+ } ) ;
22
+ </ script >
You can’t perform that action at this time.
0 commit comments