107 lines
2.7 KiB
JavaScript
107 lines
2.7 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;
|
|
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;
|
|
|
|
});
|
|
},
|
|
loginemail() {
|
|
firebase.auth().signInWithEmailAndPassword(this.email, this.password).then(result => {
|
|
checkAuth();
|
|
}).catch(function (error) {
|
|
// Handle Errors here.
|
|
var errorCode = error.code;
|
|
var errorMessage = error.message;
|
|
// ...
|
|
});
|
|
}
|
|
|
|
},
|
|
|
|
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);
|
|
// });
|
|
// }
|
|
|
|
}); |