Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- // Get elements
- const txtEmail = document.getElementById('txtEmail');
- const txtPassword = document.getElementById('txtPassword');
- const btnDoLogin = document.getElementById('btnDoLogin');
- // Login event
- btnDoLogin.addEventListener('click', e => {
- // Get email and password
- const email = txtEmail.value;
- const password = txtPassword.value;
- const auth = firebase.auth();
- // Sign in
- const promise = auth.signInWithEmailAndPassword(email, password);
- promise.catch(e => document.getElementById("errorThings").innerHTML = e.message);
- });
- // Add realtime listener
- firebase.auth().onAuthStateChanged(firebaseUser => {
- if(firebaseUser){
- firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idToken) {
- console.log(idToken)
- window.location = '/doLoginIn/' + idToken;
- // Send token to your backend via HTTPS
- // ...
- }).catch(function(error) {
- // Handle error
- });
- } else {
- console.log('not logged in');
- }
- });
- </script>
- decoded_token = auth.verify_id_token(id_token)
- @app.route("/login")
- def login():
- return render_template("login.html")
- @app.route("/doLoginIn")
- @app.route("/doLoginIn/<id_token>")
- def doLoginIn(id_token=None):
- try:
- decoded_token = auth.verify_id_token(id_token)
- print(decoded_token)
- session['email'] = decoded_token['email']
- session['loggedOn'] = True
- return redirect("/dashboard")
- except:
- return redirect("/login")
- @app.route("/dashboard")
- def dashboard():
- return render_template("dashboard.html")
Add Comment
Please, Sign In to add comment