Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Google Authentication to the Application #340 #504

Merged
merged 4 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions login/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const firebaseConfig = {
apiKey: process.env.FIREBASE_API_KEY,
authDomain: process.env.FIREBASE_AUTH_DOMAIN,
projectId: process.env.FIREBASE_PROJECT_ID,
storageBucket: process.env.FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.FIREBASE_MESSAGING_SENDER_ID,
appId: process.env.FIREBASE_APP_ID,
};
33 changes: 33 additions & 0 deletions login/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.14.1/firebase-app.js";

import { getAuth, GoogleAuthProvider, signInWithPopup } from "https://www.gstatic.com/firebasejs/10.14.1/firebase-auth.js";

const firebaseConfig = {
apiKey: process.env.FIREBASE_API_KEY,
authDomain: process.env.FIREBASE_AUTH_DOMAIN,
projectId: process.env.FIREBASE_PROJECT_ID,
storageBucket: process.env.FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.FIREBASE_MESSAGING_SENDER_ID,
appId: process.env.FIREBASE_APP_ID,
};

const app = initializeApp(firebaseConfig);
const auth =getAuth(app);
auth.languageCode ="en"
const provider=new GoogleAuthProvider();
console.log("hello");
const googleLogin =document.getElementById('google-login-btn');
googleLogin.addEventListener('click', function(){
signInWithPopup(auth, provider)
.then((result) => {
const credential = GoogleAuthProvider.credentialFromResult(result);
const user = result.user;
console.log(user);
window.location.href="../index.html";

}).catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;

});
});
4 changes: 3 additions & 1 deletion login/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<script src="https://unpkg.com/[email protected]/dist/ionicons.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css">
<link rel="stylesheet" href="login.css">
<script src="auth.js" defer type="module"></script>

</head>
<body>
<div class="button-container">
Expand Down Expand Up @@ -39,7 +41,7 @@ <h1 class="login-title">Welcome to Gaming Tools Store!</h1>
</div>
<div class="social-login">
<p>Or Login With</p>
<button type="button" class="social-button google">Login with Google</button>
<button id='google-login-btn' class="social-button google">Login with Google</button>
</div>
</div>
</div>
Expand Down