101 lines
2.9 KiB
JavaScript
101 lines
2.9 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);
|
|
|
|
|
|
function checkAuth(){
|
|
firebase.auth().onAuthStateChanged(async function(user){
|
|
if(user){
|
|
try{
|
|
firebase.auth().currentUser.getIdToken(/* forceRefresh */ 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)
|
|
}
|
|
})
|
|
var user = firebase.auth().currentUser;
|
|
}
|
|
window.onload = function(){
|
|
checkAuth();
|
|
}
|
|
|
|
|
|
|
|
var vue = new Vue({
|
|
el: '#vue-app',
|
|
data:{
|
|
|
|
},
|
|
methods: {
|
|
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;
|
|
console.log("Eingelogt");
|
|
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;
|
|
|
|
});
|
|
}
|
|
|
|
},
|
|
<<<<<<< HEAD
|
|
mounted() {
|
|
/*axios.post('/user', {
|
|
message_id: 'test',
|
|
})
|
|
.then(function (response) {
|
|
console.log(response);
|
|
})
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
});*/
|
|
}
|
|
=======
|
|
// mounted() {
|
|
// axios.post('/user', {
|
|
// message_id: 'test',
|
|
// })
|
|
// .then(function (response) {
|
|
// console.log(response);
|
|
// })
|
|
// .catch(function (error) {
|
|
// console.log(error);
|
|
// });
|
|
// }
|
|
>>>>>>> 51e8fe7ad3886f317cd447a9b70b535cd6668806
|
|
}); |