Skip to content

Commit

Permalink
feat(core): ✨ implemented a feature which will allow users to login w…
Browse files Browse the repository at this point in the history
…ith linkedIn

implemented a feature which will allow users to login with linkedIn

ref: wrappid#382
  • Loading branch information
MihirRajChowdhury committed Oct 7, 2024
1 parent ba7c929 commit 9461e3b
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions package/components/inputs/custom/LinkedInAuthComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,16 @@ import React, { useState, useEffect } from "react";
import { NativeLinkedInAuthComponent } from "@wrappid/native";
// eslint-disable-next-line import/no-unresolved
import { WrappidDataContext } from "@wrappid/styles";
import { useDispatch } from "react-redux";

import CoreButton from "./../CoreButton";
import { HTTP } from "../../../config/constants";
import { apiRequestAction } from "../../../store/action/appActions";
import CoreBox from "../../layouts/CoreBox";

const fetchUserData = async (authCode) => {
// Send access token to backend to exchange for long-lived token
const response = await fetch("http://localhost:8080/social/login/linkedin", {
body : JSON.stringify({ authCode }),
headers: { "Content-Type": "application/json" },
method : "POST",
});

// eslint-disable-next-line no-unused-vars
const data = await response.json();

};

export default function LinkedInAuthComponent(props){
const { config } = React.useContext(WrappidDataContext);
const dispatch = useDispatch();

const clientId = config?.wrappid?.socialLogin?.linkedin?.apiKey;
const redirectUri = config?.wrappid?.socialLogin?.linkedin?.callbackURL;
Expand All @@ -39,28 +30,40 @@ export default function LinkedInAuthComponent(props){
// Redirect user to LinkedIn auth URL
window.location.href = authUrl;
};
const fetchUserData = (authCode) => {
const data = { platformToken: authCode };

dispatch(
apiRequestAction(
HTTP.POST,
"/login/social/linkedin",
false,
data,
"LOGIN_SUCCESS",
"LOGIN_ERROR"
)
);
};
const [authCode, setAuthCode] = useState(null);

useEffect(() => {
// Extract the authorization code from the URL
const queryParams = new URLSearchParams(window.location.search);
const code = queryParams.get("code");

if (code) {
if (code != null) {
setAuthCode(code);
}

console.log("AuthCode from useState", authCode);
if(authCode){
if(authCode !== null){
// eslint-disable-next-line no-unused-vars

fetchUserData(authCode);
}
}, [authCode]);

return (
<CoreBox>
<NativeLinkedInAuthComponent onClick={handleClick} {...props}/>
<NativeLinkedInAuthComponent onClick={handleClick} {...props} label="LinkedIn"/>
</CoreBox>
);
}
Expand Down

0 comments on commit 9461e3b

Please sign in to comment.