-
Notifications
You must be signed in to change notification settings - Fork 50
/
firebase.html
117 lines (107 loc) · 4.02 KB
/
firebase.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/8.2.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.1/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.1/firebase-firestore.js"></script>
<!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#available-libraries -->
<script src="https://www.gstatic.com/firebasejs/8.2.1/firebase-analytics.js"></script>
<script>
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
var firebaseConfig = {
apiKey: 'AIzaSyDF2zYbdahX3vpiBBzEqDdFnno-a5qHoKc',
authDomain: 'find-mentor-network.firebaseapp.com',
projectId: 'find-mentor-network',
storageBucket: 'find-mentor-network.appspot.com',
messagingSenderId: '76703417205',
appId: '1:76703417205:web:60baa4a580dd7722f2c93c',
measurementId: 'G-LC5S8G47R2',
}
// Initialize Firebase
firebase.initializeApp(firebaseConfig)
firebase.analytics()
const db = firebase.firestore()
firebase.auth().onAuthStateChanged(async (user) => {
if (user) {
// Get user profile
let profile = await db
.doc(`peer/${user.uid}`)
.get()
.then((snap) => snap.data())
console.log(profile)
// this.login({...user, profile})
console.log('Giris yapildi')
} else {
try {
// await this.$fireAuthObj().signOut()
// this.logout()
console.log('Cikis yapildi')
} catch (e) {
// console.log(e)
}
}
})
var provider = new firebase.auth.GithubAuthProvider()
provider.addScope('read:user')
const register = async (data) => db.doc(`/peer/${data.uid}`).set(data, { merge: true })
const login = () => {
firebase
.auth()
.signInWithPopup(provider)
.then(async (result) => {
// This gives you a GitHub Access Token. You can use it to access the GitHub API.
const token = result.credential.accessToken
const profile = result.additionalUserInfo.profile
// The signed-in user info.
const user = result.user
delete profile.plan
delete profile.type
profile.avatar = `https://avatars.githubusercontent.com/${profile.login}`
const registered = await register({
...profile,
token,
uid: user.uid,
isNewUser: result.additionalUserInfo.isNewUser,
})
console.log(registered)
// Check user twitter_address
// Check user isNewUser
})
.catch(function (error) {
// Handle Errors here.
const errorCode = error.code
const errorMessage = error.message
// The email of the user's account used.
const email = error.email
// The firebase.auth.AuthCredential type that was used.
const credential = error.credential
// ...
})
}
const getTypeOfUsers = async (type = 'mentee') =>
db
.collection('peer')
.where('type', 'array-contains', type)
.get()
.then((snap) => snap.docs.map((doc) => doc.data()))
const getUser = async (slug) =>
db
.collection('peer')
.where('login', '==', slug)
.get()
.then((snap) => snap.docs.map((doc) => doc.data()))
window.getTypeOfUsers = getTypeOfUsers
window.getUser = getUser
window.login = login
// login()
</script>
</body>
</html>