mongodb-stitch
Version:
[](https://gitter.im/mongodb/stitch?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
42 lines (37 loc) • 1.32 kB
HTML
<html>
<head>
<script src="http://localhost:8005/stitch.js"></script>
<script>
let client;
let db;
function initStitchClient() {
stitch.StitchClientFactory.create(
document.getElementById('client-app-id-input').value,
{baseUrl: "http://localhost:9090"})
.then(sc => {
client = sc;
db = client.service('mongodb', 'mongodb-atlas').db('blog');
});
}
function authenticateWithFacebook() {
client.authenticate('facebook');
}
function updateAuthStatus() {
var authStatus = client.isAuthenticated ? client.authedId() : "Logged out.";
var userProfile = client.userProfile().then(profile=> {
document.getElementById("auth-status").innerText = profile.identities[0].provider_type;
});
}
</script>
</head>
<body>
<h3>Authentication Status</h3>
<div id="auth-status">
Logged out.
</div>
<input id="client-app-id-input"/>
<button id="init-stitch-button" onclick="initStitchClient()">Initialize Stitch</button>
<button id="fb-oauth-button" onclick="authenticateWithFacebook()">Authenticate with Facebook</button>
<button id="update-auth-status-button" onclick="updateAuthStatus()">Update Auth Status</button>
</body>
</html>