Skip to content

Commit 15c9306

Browse files
committed
Update Facebook integration
1 parent 1f2ad33 commit 15c9306

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ NEXT_PUBLIC_GOOGLE_OAUTH_CLIENT_ID=<your-google-oauth-client-id>
66
NEXT_PUBLIC_APPLE_OAUTH_CLIENT_ID=<your-apple-oauth-client-id>
77
NEXT_PUBLIC_FACEBOOK_CLIENT_ID=<your-facebook-oauth-client-id>
88
NEXT_PUBLIC_FACEBOOK_GRAPH_API_VERSION=21.0
9-
NEXT_PUBLIC_FACEBOOK_AUTH_VERSION=11.0
9+
NEXT_PUBLIC_FACEBOOK_AUTH_VERSION=21.0
1010
# Sensitive values ideally for server only
1111

1212
ALCHEMY_API_KEY=

src/actions/turnkey.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,32 @@ export async function exchangeToken(code: string, codeVerifier: string) {
5858
const url = `https://graph.facebook.com/v${graphAPIVersion}/oauth/access_token`
5959

6060
const clientID = env.NEXT_PUBLIC_FACEBOOK_CLIENT_ID
61+
const clientSecret = env.FACEBOOK_APP_SECRET
6162
const redirectURI = `${siteConfig.url.base}/oauth-callback/facebook`
6263

6364
const params = new URLSearchParams({
6465
client_id: clientID,
66+
client_secret: clientSecret,
6567
redirect_uri: redirectURI,
6668
code: code,
6769
code_verifier: codeVerifier,
6870
})
6971

7072
try {
71-
const target = `${url}?${params.toString()}`
72-
73-
const response = await fetch(target, {
74-
method: "GET",
73+
const response = await fetch(url, {
74+
method: "POST",
75+
headers: {
76+
"Content-Type": "application/x-www-form-urlencoded",
77+
},
78+
body: params.toString(),
7579
})
7680

7781
if (!response.ok) {
78-
throw new Error(`Token exchange failed: ${response.statusText}`)
82+
const errorText = await response.text()
83+
console.error("Facebook token exchange error:", errorText)
84+
throw new Error(
85+
`Token exchange failed: ${response.statusText} - ${errorText}`
86+
)
7987
}
8088

8189
const data = await response.json()

src/env.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const env = createEnv({
2323
NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL: z.string().optional(),
2424
NEXT_PUBLIC_APP_URL: z.string().optional(),
2525
FACEBOOK_SECRET_SALT: z.string().min(1),
26+
FACEBOOK_APP_SECRET: z.string().min(1),
2627
NEXT_PUBLIC_FACEBOOK_CLIENT_ID: z.string().min(1),
2728
NEXT_PUBLIC_FACEBOOK_GRAPH_API_VERSION: z.string().min(1),
2829
TURNKEY_API_PUBLIC_KEY: z.string().min(1),
@@ -52,6 +53,7 @@ export const env = createEnv({
5253
NEXT_PUBLIC_APP_URL: process.env.NEXT_PUBLIC_APP_URL,
5354
NEXT_PUBLIC_BASE_URL: process.env.NEXT_PUBLIC_BASE_URL,
5455
FACEBOOK_SECRET_SALT: process.env.FACEBOOK_SECRET_SALT,
56+
FACEBOOK_APP_SECRET: process.env.FACEBOOK_APP_SECRET,
5557
TURNKEY_API_PUBLIC_KEY: process.env.TURNKEY_API_PUBLIC_KEY,
5658
TURNKEY_API_PRIVATE_KEY: process.env.TURNKEY_API_PRIVATE_KEY,
5759
NEXT_PUBLIC_ORGANIZATION_ID: process.env.NEXT_PUBLIC_ORGANIZATION_ID,

0 commit comments

Comments
 (0)