-
Notifications
You must be signed in to change notification settings - Fork 2
/
login.js
49 lines (42 loc) · 1.74 KB
/
login.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
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.9.0/firebase-app.js";
import { getAuth, signInWithPopup,GoogleAuthProvider } from "https://www.gstatic.com/firebasejs/9.9.0/firebase-auth.js";
const firebaseConfig = {
apiKey: "AIzaSyBxWd0UQOpBNVrVHJg7IiQvY65ag_dtMQY",
authDomain: "website-rater-dee9c.firebaseapp.com",
databaseURL: "https://website-rater-dee9c-default-rtdb.firebaseio.com",
projectId: "website-rater-dee9c",
storageBucket: "website-rater-dee9c.appspot.com",
messagingSenderId: "181978904864",
appId: "1:181978904864:web:5435aad37560004eadbf45",
measurementId: "G-NW16W4D4C5",
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const provider = new GoogleAuthProvider(app);
const auth = getAuth(app);
function authent(){
console.log("started");
signInWithPopup(auth, provider)
.then((result) => {
const credential = GoogleAuthProvider.credentialFromResult(result);
const token = credential.accessToken;
const user = result.user;
console.log(token);
console.log(user);
document.cookie=`token = ${token}`;
document.cookie=`user_name = ${user.displayName}`;
document.cookie=`email = ${user.email} `;
document.cookie=`phone = ${user.phoneNumber}`;
document.cookie=`pic=${user.photoURL}`;
window.location.assign('./Profile.html');
}).catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
const email = error.customData.email;
const credential = GoogleAuthProvider.credentialFromError(error);
// ...
});
}
if(
document.getElementById('google')){
document.getElementById('google').addEventListener("click",()=>{authent();});}