Skip to content

Commit

Permalink
Merge pull request #562 from Ojas-Arora/dev
Browse files Browse the repository at this point in the history
Adding LinkedIn Authentication
  • Loading branch information
SUGAM-ARORA authored Jul 25, 2024
2 parents c1fff34 + b6ffd78 commit fd9006c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/Components/Firebase/Firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
GithubAuthProvider,
FacebookAuthProvider,
TwitterAuthProvider,
OAuthProvider, // Import OAuthProvider for Microsoft
OAuthProvider, // Import OAuthProvider for LinkedIn
signInWithPopup,
RecaptchaVerifier,
signInWithPhoneNumber
Expand All @@ -29,12 +29,14 @@ const firebaseConfig = {
const firebaseApp = initializeApp(firebaseConfig);
const analytics = getAnalytics(firebaseApp);
const db = getFirestore(firebaseApp);
const auth = getAuth(firebaseApp);

const googleProvider = new GoogleAuthProvider();
const githubProvider = new GithubAuthProvider();
const facebookProvider = new FacebookAuthProvider();
const twitterProvider = new TwitterAuthProvider();
const microsoftProvider = new OAuthProvider('microsoft.com'); // Initialize Microsoft provider
const auth = getAuth(firebaseApp);
const linkedinProvider = new OAuthProvider('linkedin.com'); // Initialize LinkedIn provider

export {
auth,
Expand All @@ -43,10 +45,8 @@ export {
githubProvider,
facebookProvider,
twitterProvider,
microsoftProvider, // Export Microsoft provider
GithubAuthProvider,
FacebookAuthProvider,
TwitterAuthProvider,
microsoftProvider,
linkedinProvider,
RecaptchaVerifier,
signInWithPhoneNumber
};
Expand Down
23 changes: 18 additions & 5 deletions src/Components/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import '@fortawesome/fontawesome-free/css/all.min.css';
import logImg from './Profile/log.svg';
import registerImg from './Profile/register.svg';
import homeIcon from './FreeLancer/homeicon.png';
import { auth, googleProvider, githubProvider, facebookProvider, microsoftProvider } from './Firebase/Firebase.js';
import { auth, googleProvider, githubProvider, facebookProvider, microsoftProvider, linkedinProvider } from './Firebase/Firebase.js';
import {
signInWithPopup,
signInWithEmailAndPassword,
Expand Down Expand Up @@ -86,6 +86,19 @@ const LogIn = () => {
}
};

// New LinkedIn sign-in handler
const handleLinkedInSignIn = async () => {
try {
const result = await signInWithPopup(auth, linkedinProvider);
const user = result.user;
localStorage.setItem('user', JSON.stringify(user));
console.log('LinkedIn sign-in success:', user);
navigate('/');
} catch (error) {
console.error('LinkedIn sign-in error:', error);
}
};

const handleLogin = async (e) => {
e.preventDefault();
const emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
Expand Down Expand Up @@ -288,9 +301,9 @@ const LogIn = () => {
<div onClick={handleGoogleSignIn} className="social-icon">
<i className="fab fa-google" style={{ color: 'darkturquoise' }}></i>
</div>
<Link to="https://www.linkedin.com" className="social-icon">
<div onClick={handleLinkedInSignIn} className="social-icon">
<i className="fab fa-linkedin-in" style={{ color: 'darkturquoise' }}></i>
</Link>
</div>
<div onClick={handleGitHubSignIn} className="social-icon">
<i className="fab fa-github" style={{ color: 'darkturquoise' }}></i>
</div>
Expand Down Expand Up @@ -389,9 +402,9 @@ const LogIn = () => {
<div onClick={handleGoogleSignIn} className="social-icon">
<i className="fab fa-google" style={{ color: 'darkturquoise' }}></i>
</div>
<Link to="https://www.linkedin.com" className="social-icon">
<div onClick={handleLinkedInSignIn} className="social-icon">
<i className="fab fa-linkedin-in" style={{ color: 'darkturquoise' }}></i>
</Link>
</div>
<div onClick={handleGitHubSignIn} className="social-icon">
<i className="fab fa-github" style={{ color: 'darkturquoise' }}></i>
</div>
Expand Down

0 comments on commit fd9006c

Please sign in to comment.