|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | + |
| 4 | +<head> |
| 5 | + <meta charset="UTF-8"> |
| 6 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 7 | + <meta http-equiv="X-UA-Compatible" content="ie=edge"> |
| 8 | + <title>Success</title> |
| 9 | + |
| 10 | + <script src="https://www.gstatic.com/firebasejs/6.0.2/firebase-app.js"></script> |
| 11 | + <script src="https://www.gstatic.com/firebasejs/6.0.2/firebase-auth.js"></script> |
| 12 | + |
| 13 | + <script> |
| 14 | + // Your web app's Firebase configuration |
| 15 | + var firebaseConfig = { |
| 16 | + apiKey: "", |
| 17 | + authDomain: "", |
| 18 | + databaseURL: "", |
| 19 | + projectId: "", |
| 20 | + storageBucket: "", |
| 21 | + messagingSenderId: "", |
| 22 | + appId: "" |
| 23 | + }; |
| 24 | + // Initialize Firebase |
| 25 | + firebase.initializeApp(firebaseConfig); |
| 26 | + </script> |
| 27 | + |
| 28 | + <script> |
| 29 | + var url = '/api.php/records/posts?join=categories&join=tags&join=comments&filter=id,eq,1'; |
| 30 | + |
| 31 | + function requestAPI(accessToken) { |
| 32 | + var req = new XMLHttpRequest(); |
| 33 | + req.onreadystatechange = function () { |
| 34 | + if (req.readyState == 4) { |
| 35 | + try { |
| 36 | + document.getElementById('output').innerHTML = JSON.stringify(JSON.parse(req.responseText), |
| 37 | + undefined, 4); |
| 38 | + } catch (error) { |
| 39 | + document.getElementById('output').innerHTML = req.responseText; |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | + req.open("GET", url, true); |
| 44 | + req.setRequestHeader('X-Authorization', 'Bearer ' + accessToken); |
| 45 | + req.send(); |
| 46 | + } |
| 47 | + |
| 48 | + function initApp() { |
| 49 | + firebase.auth().onAuthStateChanged(function (user) { |
| 50 | + if (user) { |
| 51 | + // User is signed in. |
| 52 | + var displayName = user.displayName; |
| 53 | + var email = user.email; |
| 54 | + var emailVerified = user.emailVerified; |
| 55 | + var photoURL = user.photoURL; |
| 56 | + var uid = user.uid; |
| 57 | + var phoneNumber = user.phoneNumber; |
| 58 | + var providerData = user.providerData; |
| 59 | + user.getIdToken().then(function (accessToken) { |
| 60 | + document.getElementById('sign-in-status').textContent = 'Signed in'; |
| 61 | + document.getElementById('account-details').textContent = JSON.stringify({ |
| 62 | + displayName: displayName, |
| 63 | + email: email, |
| 64 | + emailVerified: emailVerified, |
| 65 | + phoneNumber: phoneNumber, |
| 66 | + photoURL: photoURL, |
| 67 | + uid: uid, |
| 68 | + accessToken: accessToken, |
| 69 | + providerData: providerData |
| 70 | + }, undefined, 4); |
| 71 | + |
| 72 | + requestAPI(accessToken) |
| 73 | + }); |
| 74 | + } else { |
| 75 | + // User is signed out. |
| 76 | + document.getElementById('sign-in-status').textContent = 'Signed out'; |
| 77 | + document.getElementById('account-details').textContent = 'null'; |
| 78 | + } |
| 79 | + }, function (error) { |
| 80 | + console.log(error); |
| 81 | + }); |
| 82 | + }; |
| 83 | + |
| 84 | + window.addEventListener('load', initApp); |
| 85 | + </script> |
| 86 | +</head> |
| 87 | + |
| 88 | +<body> |
| 89 | + <h1>Firebase Login Success (or not)</h1> |
| 90 | + |
| 91 | + <div id="sign-in-status"></div> |
| 92 | + <pre id="account-details"></pre> |
| 93 | + |
| 94 | + <pre id="output"></pre> |
| 95 | +</body> |
| 96 | + |
| 97 | +</html> |
0 commit comments