Skip to content

Commit

Permalink
Merge pull request #118 from rogershi-dev/feature/registration-auth
Browse files Browse the repository at this point in the history
Properly fetched linkedinId from database
  • Loading branch information
rogershi-dev authored Jul 14, 2024
2 parents b72afa3 + cdc8710 commit 57f9247
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions server/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,14 @@ async function postToMastodon(messageToPost) {
}

// Function to make a post on LinkedIn
async function postToLinkedIn(message, accessToken) {
async function postToLinkedIn(message, accessToken, linkedinId) {
// Truncate the message if it's longer than 2000 characters
const truncatedMessage = truncateMessageFromEnd(message, 1500);

const url = 'https://api.linkedin.com/v2/ugcPosts';

const payload = {
author: `urn:li:person:${req.session.user[0].linkedin_id}`,
author: `urn:li:person:${linkedinId}`,
lifecycleState: 'PUBLISHED',
specificContent: {
'com.linkedin.ugc.ShareContent': {
Expand Down Expand Up @@ -297,9 +297,10 @@ router.post('/webhook', async (req, res) => {
if (rows.length > 0){
// Retrieve the linkedin-access-token
const linkedinAccessToken = rows[0].linkedin_token;
const linkedinId = rows[0].linkedin_id;

// Post to LinkedIn on behalf of the user
const postResponse = await postToLinkedIn(expandedMessage, linkedinAccessToken);
const postResponse = await postToLinkedIn(expandedMessage, linkedinAccessToken, linkedinId);
console.log('LinkedIn post response:', postResponse.data);

// Send a success response to GitHub
Expand Down

0 comments on commit 57f9247

Please sign in to comment.