Skip to content

Commit

Permalink
chore: allow saving of long token, remove debug log
Browse files Browse the repository at this point in the history
  • Loading branch information
kguzek committed Dec 14, 2024
1 parent e581b61 commit 1fbc506
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib/facebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ let getAccessTokenPromise: null | Promise<string | null> = null;
*/
async function getAccessToken() {
if (getAccessTokenPromise != null) return getAccessTokenPromise;
const existingToken = process.env.FACEBOOK_LONG_LIVED_ACCESS_TOKEN;
if (existingToken) return existingToken;
const shortLivedToken = process.env.FACEBOOK_ACCESS_TOKEN || "";
if (!shortLivedToken) {
console.error("No short-lived access token set for Facebook API");
Expand All @@ -40,6 +42,7 @@ async function getAccessToken() {
return null;
}
const path = `oauth/access_token?client_id=${clientId}&client_secret=${clientSecret}&fb_exchange_token=${shortLivedToken}&grant_type=fb_exchange_token`;
console.info("Generating long-lived access token from Facebook API...");
const response = await fetchFromFacebook<FacebookAccessToken>(
path,
"",
Expand Down Expand Up @@ -73,7 +76,6 @@ async function fetchFromFacebook<T>(
console.error("No long-lived access token set for Facebook API");
return null;
}
console.log(token);
headers["Authorization"] = `Bearer ${token}`;
}
const response = await fetch(url.toString(), { headers });
Expand Down

0 comments on commit 1fbc506

Please sign in to comment.