roshangeorge97 / Edunity

Creating a Platform where students preparing for competitive exams can connect with their Seniors to seek guidance for improving their grades on a one-one basis.
https://edunity12.azurewebsites.net/
17 stars 19 forks source link

Adding login with google #9

Open Advaita151 opened 1 year ago

Advaita151 commented 1 year ago

Current Behavior

User has to enter their email and password manually

Desired Behavior

Firebase provides google authentication which would be easier to login. I would like to work on this issue as GSSOC'23 Contributor. Thank you !

Could you please assign this issue to me?

Screenshots / Mockups


screenshot

ezzycodesishaan commented 1 year ago

import com.google.firebase.FirebaseApp; import com.google.firebase.auth.FirebaseAuth; import com.google.firebase.auth.FirebaseAuthProvider; import com.google.firebase.auth.FirebaseToken; import com.google.firebase.auth.GoogleAuthProvider;

// Initialize FirebaseApp (Make sure you have already set up your Firebase project) FirebaseApp.initializeApp();

// Get the FirebaseAuth instance FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();

// Generate a Google authentication provider FirebaseAuthProvider firebaseAuthProvider = GoogleAuthProvider.getInstance();

// Authenticate with Firebase using Google credentials String idToken = ""; // Replace with the actual Google ID token firebaseAuthProvider.verifyToken(idToken) .addOnCompleteListener(task -> { if (task.isSuccessful()) { // Authentication successful FirebaseToken firebaseToken = task.getResult(); String uid = firebaseToken.getUid(); String email = firebaseToken.getEmail(); System.out.println("Authenticated user - UID: " + uid + ", Email: " + email); } else { // Authentication failed Exception exception = task.getException(); System.out.println("Authentication failed: " + exception.getMessage()); } });

we have to first set up a firebase first in java program first.

roshangeorge97 commented 1 year ago

This would be great if achieved. I am assigning you this issue, goodluck!

ezzycodesishaan commented 1 year ago

Thanks a lot i will try my best

On Mon, 22 May 2023, 22:09 Roshan George, @.***> wrote:

This would be great if achieved. I am assigning you this issue, goodluck!

— Reply to this email directly, view it on GitHub https://github.com/roshangeorge97/Edunity/issues/9#issuecomment-1557551012, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZCARFS5WVJ5VA3LWY7S7TTXHOJDNANCNFSM6AAAAAAYKRJ3VM . You are receiving this because you commented.Message ID: @.***>

Advaita151 commented 1 year ago

This would be great if achieved. I am assigning you this issue, goodluck!

Thanks a lot , I will complete it asap

ezzycodesishaan commented 1 year ago

dependencies { // Firebase Authentication implementation 'com.google.firebase:firebase-auth:21.0.1' // Other Firebase SDKs you may need // implementation 'com.google.firebase:firebase-database:21.0.1' // implementation 'com.google.firebase:firebase-storage:21.0.1' // ... }

we have to add these to the dependencies section in the #build file of the edunity.

i hope this resolves the issue

first the firebase sdk is set up the the previous comment #code can solve it

roshangeorge97 commented 1 year ago

wondering If you could set up edunity locally, and give a fix by adding the snippet to the Auth component we could consider for a merge.

ezzycodesishaan commented 1 year ago

// Import the necessary Firebase modules import firebase from 'firebase/app'; import 'firebase/auth';

// Initialize Firebase (Make sure you have already set up your Firebase project) const firebaseConfig = { // Your Firebase config object goes here }; firebase.initializeApp(firebaseConfig);

// Get the Firebase auth instance const auth = firebase.auth();

// Create a Google authentication provider const provider = new firebase.auth.GoogleAuthProvider();

// Function to handle Google sign-in function signInWithGoogle() { auth.signInWithPopup(provider) .then((result) => { // Successful authentication const user = result.user; console.log('Authenticated user:', user); }) .catch((error) => { // Failed authentication console.log('Authentication failed:', error.message); }); }

// Call the signInWithGoogle function when the login button is clicked const loginButton = document.getElementById('login-button'); loginButton.addEventListener('click', signInWithGoogle);

This is a code for the authentication folder in JavaScript can merge it in the edunity main code.

html file