Georg Reisinger 471089fd19 User bearbeiten fix
Noch ein fix
2019-05-15 19:58:41 +02:00

75 lines
2.1 KiB
JavaScript

// Initialize Firebase
var config = {
apiKey: "AIzaSyCuvwf78cmSDoZ2yS4XxHZhnjUn7yIHYfw",
authDomain: "test-667ca.firebaseapp.com",
databaseURL: "https://test-667ca.firebaseio.com",
projectId: "test-667ca",
storageBucket: "test-667ca.appspot.com",
messagingSenderId: "221332577314"
};
firebase.initializeApp(config);
async function checkAuth() {
await firebase.auth().onAuthStateChanged(async function (user) {
if (user) {
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);
});
}
});
}
window.onload = function () {
checkAuth();
};
var vue = new Vue({
el: '#vue-app',
data: {
email: "",
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');
provider.addScope('email');
firebase.auth().signInWithPopup(provider).then(function (result) {
// This gives you a Google Access Token. You can use it to access the Google API.
var token = result.credential.accessToken;
var idToken = result.credential.idToken;
// The signed-in user info.
var user = result.user;
checkAuth();
}).catch(function (error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
alert(errorMessage);
});
},
loginemail() {
firebase.auth().signInWithEmailAndPassword(this.email, this.password).then(result => {
checkAuth();
}).catch(function (error) {
var errorCode = error.code;
var errorMessage = error.message;
});
}
}
});