-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathknow-token.html
90 lines (82 loc) · 2.83 KB
/
know-token.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>auth</title>
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/11.5.0/firebase-app.js";
import {
getAuth,
onAuthStateChanged,
signInWithPopup,
GithubAuthProvider,
} from "https://www.gstatic.com/firebasejs/11.5.0/firebase-auth.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyBgOE3pM-1o8_xHuK6hapMDUIM19vnxfqo",
authDomain: "chelajs.firebaseapp.com",
projectId: "chelajs",
storageBucket: "chelajs.firebasestorage.app",
messagingSenderId: "972855457624",
appId: "1:972855457624:web:ac3e5b6372810324df972d",
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
let session = null;
onAuthStateChanged(auth, async (stateSession) => {
session = stateSession;
console.log("🚀 ~ onAuthStateChanged ~ session:", session);
if (stateSession === null) {
const githubProvider = new GithubAuthProvider();
const result = await signInWithPopup(auth, githubProvider);
console.log("🚀 ~ onAuthStateChanged ~ result:", result);
return;
}
document.getElementById("textarea-token").value =
await session?.getIdToken();
});
document
.getElementById("btn-copy-token")
.addEventListener("click", async () => {
navigator.clipboard.writeText(await session?.getIdToken());
document.getElementById("btn-copy-token").innerText = "Copiado!";
setTimeout(() => {
document.getElementById("btn-copy-token").innerText = "Copiar";
}, 3000);
});
setInterval(async () => {
const idToken = await session?.getIdToken();
console.log("🚀 ~ setInterval ~ idToken:", idToken);
document.getElementById("textarea-token").value = idToken;
}, 1000);
</script>
<style>
.box-textarea-token {
display: grid;
grid-template-columns: 1fr;
gap: 1em;
}
</style>
</head>
<body>
<div class="box-textarea-token">
<label for="textarea-token">Token:</label>
<textarea
name="textarea-token"
id="textarea-token"
cols="30"
rows="10"
id=""
disabled
></textarea>
<div class="buttons">
<button id="btn-copy-token">Copiar</button>
</div>
</div>
</body>
</html>