У меня проблема с определением используемого кода, который перенаправляет пользователя на другую страницу, так как я скопировал код из inte rnet, но я испытываю трудности при попытке перенаправить пользователя после входа в систему; и мне нужно убедиться, что пользователь вошел в систему не потому, что у него есть ссылка, чтобы он мог видеть страницу, на которую я хочу указать, я использую firebase.google.com, чтобы проверить, что пользователь здесь - это мое приложение. js файл
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
document.getElementById("user_div").style.display = "block";
document.getElementById("login_div").style.display = "none";
var user = firebase.auth().currentUser;
if(user != null){
var email_id = user.email;
document.getElementById("user_para").innerHTML = "Welcome:" + email_id;
}
} else {
// No user is signed in.
document.getElementById("user_div").style.display = "none";
document.getElementById("login_div").style.display = "block";
}
});
function login(){
var userEmail = document.getElementById("email_field").value;
var userPass = document.getElementById("password_field").value;
firebase.auth().signInWithEmailAndPassword(userEmail, userPass).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
window.alert("Error : " + errorMessage);
// ...
});
}
function logout(){
firebase.auth().signOut();
}
auth.onAuthStateChanged(function(user){
if(user){
//is signed in
}else{
alert("you are not logged in");
//not signed in
}
});
*{
direction: rtl;
}
body {
background: #fff;
padding: 0px;
margin: 0px;
font-family: 'Nunito', sans-serif;
font-size: 16px;
}
input, button {
font-family: 'Nunito', sans-serif;
font-weight: 700;
}
.logo{
display: block;
margin-left: auto;
margin-right: auto;
width: 128px;
height: 128px;
}
.main-div, .loggedin-div {
width: 20%;
margin: 0px auto;
margin-top: 150px;
padding: 20px;
display: none;
}
.main-div input {
display: block;
border: 1px solid #ccc;
border-radius: 5px;
background: #fff;
padding: 15px;
outline: none;
width: 100%;
margin-bottom: 20px;
transition: 0.3s;
-webkit-transition: 0.3s;
-moz-transition: 0.3s;
}
.main-div input:focus {
border: 1px solid #777;
}
.main-div button, .loggedin-div button {
background: #5d8ffc;
color: #fff;
border: 1px solid #5d8ffc;
border-radius: 5px;
padding: 15px;
display: block;
width: 100%;
transition: 0.3s;
-webkit-transition: 0.3s;
-moz-transition: 0.3s;
}
.main-div button:hover, .loggedin-div button:hover {
background: #fff;
color: #5d8ffc;
border: 1px solid #5d8ffc;
cursor: pointer;
}
![image](./images/logo.png)
Мне нужна ваша помощь, пожалуйста:)