Last active
August 9, 2018 11:44
-
-
Save ryosuke-hujisawa/d5cad19b7b633a53b2ff6becdd1de8f9 to your computer and use it in GitHub Desktop.
How to use auth on firebase with GitHub ?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<!-- | |
Please use http or https | |
Please register your url to firebase | |
Please bond GitHub and firebase | |
--> | |
<head> | |
<title>Firebase Github Auth</title> | |
</head> | |
<body> | |
<button onclick = "githubCheck()">Github Check</button> | |
<button onclick = "githubSignin()">Github Signin</button> | |
<button onclick = "githubSignout()">Github Signout</button> | |
</body> | |
</html> | |
<script src="https://www.gstatic.com/firebasejs/5.3.0/firebase.js"></script> | |
<script> | |
/* | |
* | |
* | |
* | |
* specify your config | |
* | |
* | |
*/ | |
var config = { | |
apiKey: "AIza......", | |
authDomain: "test......", | |
databaseURL: "http......", | |
projectId: "test......", | |
storageBucket: "test......", | |
messagingSenderId: "1230......" | |
}; | |
firebase.initializeApp(config); | |
//Initialize firebase auth, than you can use. | |
var provider = new firebase.auth.GithubAuthProvider(); | |
// Users who are currently approved. | |
var user = firebase.auth().currentUser; | |
/* | |
* | |
* | |
* alredy have auth user? | |
* | |
* | |
* | |
*/ | |
function githubCheck() { | |
var name, email, photoUrl, uid, emailVerified; | |
if (user != null) { | |
name = user.displayName; | |
email = user.email; | |
photoUrl = user.photoURL; | |
emailVerified = user.emailVerified; | |
uid = user.uid; | |
console.log(name); | |
console.log(email); | |
console.log(photoUrl); | |
}else{ | |
console.log("null"); | |
} | |
} | |
/* | |
* | |
* | |
* | |
* signin | |
* | |
* | |
*/ | |
function githubSignin() { | |
firebase.auth().signInWithPopup(provider).then(function(result) { | |
}).catch(function(error) { | |
console.log("err") | |
var errorCode = error.code; | |
console.log(errorCode) | |
var errorMessage = error.message; | |
console.log(errorMessage); | |
var email = error.email; | |
console.log(email); | |
var credential = error.credential; | |
console.log(credential); | |
}); | |
} | |
/* | |
* | |
* | |
* | |
* signout and delete | |
* | |
* | |
*/ | |
function githubSignout(){ | |
user.delete().then(function() { | |
console.log("User deleted"); | |
}).catch(function(error) { | |
console.log("An error happened"); | |
}); | |
firebase.auth().signOut().then(function() { | |
console.log("ign-out successful"); | |
}).catch(function(error) { | |
console.log("An error happened"); | |
}); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment