Firebase Update
This commit is contained in:
76
express-server/public/javascripts/login.js
Normal file
76
express-server/public/javascripts/login.js
Normal file
@ -0,0 +1,76 @@
|
||||
|
||||
|
||||
// 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;
|
||||
|
||||
});
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user