Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/polar-betterauth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@polar-sh/better-auth",
"version": "1.1.3",
"version": "1.1.4",
"description": "Polar integration for better-auth",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
Expand Down
20 changes: 15 additions & 5 deletions packages/polar-betterauth/src/plugins/checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export const checkout =
.optional(),
allowDiscountCodes: z.coerce.boolean().optional().default(true),
discountId: z.string().optional(),
redirect: z.coerce.boolean().optional().default(true),
successQueryParams: z.record(z.string(), z.string()).optional(),
}),
},
async (ctx) => {
Expand Down Expand Up @@ -98,11 +100,19 @@ export const checkout =
externalCustomerId: session?.user.id,
products: productIds,
successUrl: checkoutOptions.successUrl
? new URL(
? (() => {
const url = new URL(
checkoutOptions.successUrl,
ctx.request?.url,
).toString()
: undefined,
ctx.request?.url
);
if (ctx.body.successQueryParams) {
Object.entries(ctx.body.successQueryParams).forEach(([key, value]) => {
url.searchParams.set(key, value);
});
}
return url.toString();
})()
: undefined,
metadata: ctx.body.referenceId
? {
referenceId: ctx.body.referenceId,
Expand All @@ -122,7 +132,7 @@ export const checkout =

return ctx.json({
url: redirectUrl.toString(),
redirect: true,
redirect: ctx.body?.redirect ?? true,
});
} catch (e: unknown) {
if (e instanceof Error) {
Expand Down
5 changes: 4 additions & 1 deletion packages/polar-betterauth/src/plugins/portal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export const portal = () => (polar: Polar) => {
{
method: "GET",
use: [sessionMiddleware],
query: z.object({
redirect: z.coerce.boolean().optional().default(true)
}).optional(),
},
async (ctx) => {
if (!ctx.context.session?.user.id) {
Expand All @@ -26,7 +29,7 @@ export const portal = () => (polar: Polar) => {

return ctx.json({
url: customerSession.customerPortalUrl,
redirect: true,
redirect: ctx.query?.redirect ?? true,
});
} catch (e: unknown) {
if (e instanceof Error) {
Expand Down