Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Refactor PayPal OAuth implementation: streamline token handling, update redirect URI, and simplify schema structure

Kiran Keb1a0adcbfdc
diff --git a/apps/web/app/(ee)/api/paypal/callback/route.ts b/apps/web/app/(ee)/api/paypal/callback/route.ts
index c5fea39b17..65f8318793 100644
--- a/apps/web/app/(ee)/api/paypal/callback/route.ts
+++ b/apps/web/app/(ee)/api/paypal/callback/route.ts
@@ -32,9 +32,7 @@ export const GET = async (req: Request) => {
throw new Error("partner_not_found");
}
- const {
- token: { token },
- } = await paypalOAuthProvider.exchangeCodeForToken(req);
+ const { token } = await paypalOAuthProvider.exchangeCodeForToken(req);
const paypalUser = await paypalOAuthProvider.getUserInfo(
token.access_token,
diff --git a/apps/web/lib/actions/partners/generate-paypal-oauth-url.ts b/apps/web/lib/actions/partners/generate-paypal-oauth-url.ts
index 311285e41e..2a67bda209 100644
--- a/apps/web/lib/actions/partners/generate-paypal-oauth-url.ts
+++ b/apps/web/lib/actions/partners/generate-paypal-oauth-url.ts
@@ -6,7 +6,7 @@ import { authPartnerActionClient } from "../safe-action";
export const generatePaypalOAuthUrl = authPartnerActionClient.action(
async ({ ctx }) => {
- let { partner, user } = ctx;
+ const { partner, user } = ctx;
if (!partner.country) {
throw new Error(
diff --git a/apps/web/lib/paypal/oauth.ts b/apps/web/lib/paypal/oauth.ts
index 3a12006504..70a9322b5b 100644
--- a/apps/web/lib/paypal/oauth.ts
+++ b/apps/web/lib/paypal/oauth.ts
@@ -40,9 +40,10 @@ export const paypalOAuthProvider = new PayPalOAuthProvider({
clientSecret: paypalEnv.PAYPAL_CLIENT_SECRET!,
authUrl: paypalEnv.PAYPAL_AUTHORIZE_URL,
tokenUrl: `${paypalEnv.PAYPAL_API_HOST}/v1/oauth2/token`,
- redirectUri: `${APP_DOMAIN_WITH_NGROK}/api/hubspot/callback`,
+ redirectUri: `${APP_DOMAIN_WITH_NGROK}/api/paypal/callback`,
redisStatePrefix: "paypal:oauth:state",
scopes: ["email"].join(" "),
tokenSchema: paypalAuthTokenSchema,
bodyFormat: "form",
+ authorizationMethod: "header",
});
diff --git a/apps/web/lib/paypal/schema.ts b/apps/web/lib/paypal/schema.ts
index cb64e0df7a..104b233db2 100644
--- a/apps/web/lib/paypal/schema.ts
+++ b/apps/web/lib/paypal/schema.ts
@@ -1,9 +1,7 @@
import { z } from "zod";
export const paypalAuthTokenSchema = z.object({
- token: z.object({
- access_token: z.string(),
- }),
+ access_token: z.string(),
});
export const paypalUserInfoSchema = z.object({