Login, Registrieren reperiert
This commit is contained in:
@ -10,26 +10,16 @@ var config = {
|
||||
firebase.initializeApp(config);
|
||||
|
||||
|
||||
function checkAuth() {
|
||||
firebase.auth().onAuthStateChanged(async function (user) {
|
||||
async function checkAuth() {
|
||||
await firebase.auth().onAuthStateChanged(async function (user) {
|
||||
if (user) {
|
||||
try {
|
||||
firebase.auth().currentUser.getIdToken( /* forceRefresh */ true).then(function (idToken) {
|
||||
console.log("Vor Replace");
|
||||
await firebase.auth().currentUser.getIdToken(true).then(function (idToken) {
|
||||
console.log("Vor Replace");
|
||||
|
||||
window.location.replace("/dash/" + idToken);
|
||||
}).catch(function (error) {
|
||||
console.error("Get id token client error: ", error)
|
||||
});
|
||||
} catch {
|
||||
console.error("checkAuth error: ");
|
||||
}
|
||||
|
||||
// document.getElementById("loginbutton").style.display = "none";
|
||||
//
|
||||
} else {
|
||||
// document.getElementById("loginbutton").style.display = "block";
|
||||
console.log("Check Auth error", user)
|
||||
window.location.replace("/dash/" + idToken);
|
||||
}).catch(function (error) {
|
||||
console.error("Get id token client error: ", error);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -43,9 +33,17 @@ var vue = new Vue({
|
||||
el: '#vue-app',
|
||||
data: {
|
||||
email: "",
|
||||
password: ""
|
||||
password: "",
|
||||
emailandpwd: false
|
||||
},
|
||||
methods: {
|
||||
emailpasswdfilled() {
|
||||
var filled = false;
|
||||
if (email && password) {
|
||||
filled = true;
|
||||
}
|
||||
emailandpwd = filled;
|
||||
},
|
||||
login() {
|
||||
var provider = new firebase.auth.GoogleAuthProvider();
|
||||
provider.addScope('profile');
|
||||
|
@ -15,38 +15,45 @@ var vue = new Vue({
|
||||
data: {
|
||||
name: "",
|
||||
email: "",
|
||||
picurl: "",
|
||||
password: ""
|
||||
},
|
||||
methods: {
|
||||
registerEmail() {
|
||||
async registerEmail() {
|
||||
|
||||
|
||||
console.log("Start register: ", this.name, this.email, this.password)
|
||||
|
||||
await firebase.auth().createUserWithEmailAndPassword(this.email, this.password)
|
||||
.then(user => {
|
||||
console.log("User created: ", user);
|
||||
|
||||
})
|
||||
.catch(function (error) {
|
||||
// Handle Errors here.
|
||||
var errorCode = error.code;
|
||||
var errorMessage = error.message;
|
||||
|
||||
console.error(error.code + '_' + error.message);
|
||||
alert(error.code + '_' + error.message);
|
||||
});
|
||||
var user = firebase.auth().currentUser;
|
||||
if (user != null) {
|
||||
await user.updateProfile({
|
||||
displayName: this.name,
|
||||
photoURL: "http://techfrage.de/upfiles/13547334191038217.png"
|
||||
}).then(function () {
|
||||
console.log("update name and photo");
|
||||
|
||||
firebase.auth().createUserWithEmailAndPassword(this.email, this.password).catch(function (error) {
|
||||
// Handle Errors here.
|
||||
var errorCode = error.code;
|
||||
var errorMessage = error.message;
|
||||
|
||||
console.error(error)
|
||||
// ...
|
||||
});
|
||||
|
||||
user.updateProfile({
|
||||
displayName: this.name,
|
||||
photoURL: this.picurl
|
||||
}).then(function () {
|
||||
// Update successful.
|
||||
}).catch(function (error) {
|
||||
console.error(error)
|
||||
});
|
||||
|
||||
user.updateEmail(this.email).then(function () {
|
||||
// Update successful.
|
||||
}).catch(function (error) {
|
||||
console.error(error)
|
||||
});
|
||||
|
||||
window.location.href = "/";
|
||||
}).catch(function (error) {
|
||||
console.error(error);
|
||||
});
|
||||
await user.updateEmail(this.email).then(function () {
|
||||
console.log("Email");
|
||||
}).catch(function (error) {
|
||||
console.error(error);
|
||||
});
|
||||
window.location.href = "/";
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
Reference in New Issue
Block a user