This repository has been archived by the owner on Oct 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.js
57 lines (50 loc) · 1.66 KB
/
client.js
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
window.meeshkan = {};
(async () => {
let loadScript = (script_url) => {
return new Promise(function(resolve, reject) {
let script = document.createElement('script');
script.onload = resolve;
script.src = script_url
document.head.appendChild(script);
});
}
await Promise.all([
loadScript("https://www.gstatic.com/firebasejs/7.9.1/firebase-app.js"),
loadScript("https://www.gstatic.com/firebasejs/7.9.1/firebase-auth.js")
]);
meeshkan.signOut = () => {
meeshkan.signingOut = true;
firebase.auth().signOut().then(() => {
window.location.reload();
}, (error) => {
console.error('Sign Out Error', error);
window.location.reload();
});
};
meeshkan.signIn = () => {
window.location = '/login?redirect=' + window.location.pathname.substring(1) + (window.location.search ? ('?' + encodeURIComponent(window.location.search.substring(1))) : '');
}
window.addEventListener('load', () => {
firebase.initializeApp({
apiKey: "AIzaSyBm8fh3xwQ3PMtNHvtAEaBSchSDaf9Im6U",
authDomain: "auth.meeshkan.io",
projectId: "sound-electron-268214",
appId: "1:294417890851:web:cc08162524c8ffb3317b96"
});
firebase.auth().onAuthStateChanged((user) => {
if (meeshkan.signingOut) return;
if (user) {
firebase.auth().currentUser.getIdToken(true).then((accessToken) => {
user.accessToken = accessToken;
meeshkan.onUser(user);
}).catch(function(error) {
console.error('getIdToken error', error);
});
} else {
meeshkan.onUser(null);
}
}, (error) => {
console.error(error);
});
});
})();