Created
April 14, 2019 15:36
-
-
Save Alex-Wauters/1f270363a7c1b90a34a79749a653a828 to your computer and use it in GitHub Desktop.
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
// Abbreviated version from https://github.com/Alex-Wauters/firebase-auth-azure-ad/blob/master/main.js | |
firebase.auth().onAuthStateChanged(function (user) { | |
if (user) { | |
console.log('User is logged in'); | |
startApp(); | |
} else { | |
const url = window.location.href; | |
if (url.indexOf('jwt=') > -1) { // The minted firebase token from Auth function | |
const token = url.substr( url.indexOf('jwt=') + 4); | |
firebase.auth().signInWithCustomToken(token) | |
.then((user) => { | |
window.location.href="/"; | |
}) | |
.catch(function (error) { | |
// Handle Errors here. | |
}); | |
} else { // User not authenticated and no custom token present. Redirect to Azure AD for authentication token | |
let redirectUrl = "/auth"; //TODO: Redirect to the URL of your auth function | |
if (window.location.port === "5000") { // Adjust the requested redirectUri for local development | |
redirectUrl = redirectUrl + "&redirect_uri=http%3A%2F%2Flocalhost%3A5000%2Fauth"; | |
} | |
window.location.href = redirectUrl; | |
} | |
} | |
}); | |
function startApp() { //Load front-end application | |
new Vue({ | |
el: '#app', | |
template: '<App/>', | |
components: {App} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment