feat(cli): add polar as better-auth plugin (#578)

This commit is contained in:
Aman Varshney
2025-09-16 17:53:44 +05:30
committed by GitHub
parent 3f22373cc3
commit ba3d62b6b9
77 changed files with 1221 additions and 308 deletions

View File

@@ -4,6 +4,10 @@ import { prismaAdapter } from "better-auth/adapters/prisma";
{{#if (or (includes frontend "native-nativewind") (includes frontend "native-unistyles"))}}
import { expo } from "@better-auth/expo";
{{/if}}
{{#if (eq payments "polar")}}
import { polar, checkout, portal } from "@polar-sh/better-auth";
import { polarClient } from "./payments";
{{/if}}
import prisma from "../db";
export const auth = betterAuth<BetterAuthOptions>({
@@ -28,9 +32,35 @@ export const auth = betterAuth<BetterAuthOptions>({
secure: true,
httpOnly: true,
},
}
},
{{#if (eq payments "polar")}}
plugins: [
polar({
client: polarClient,
createCustomerOnSignUp: true,
enableCustomerPortal: true,
use: [
checkout({
products: [
{
productId: "your-product-id",
slug: "pro",
},
],
successUrl: process.env.POLAR_SUCCESS_URL,
authenticatedUsersOnly: true,
}),
portal(),
],
}),
{{#if (or (includes frontend "native-nativewind") (includes frontend "native-unistyles"))}}
expo(),
{{/if}}
],
{{else}}
{{#if (or (includes frontend "native-nativewind") (includes frontend "native-unistyles"))}}
, plugins: [expo()]
plugins: [expo()],
{{/if}}
{{/if}}
});
{{/if}}
@@ -42,6 +72,10 @@ import { drizzleAdapter } from "better-auth/adapters/drizzle";
{{#if (or (includes frontend "native-nativewind") (includes frontend "native-unistyles"))}}
import { expo } from "@better-auth/expo";
{{/if}}
{{#if (eq payments "polar")}}
import { polar, checkout, portal } from "@polar-sh/better-auth";
import { polarClient } from "./payments";
{{/if}}
import { db } from "../db";
import * as schema from "../db/schema/auth";
@@ -68,9 +102,35 @@ export const auth = betterAuth<BetterAuthOptions>({
httpOnly: true,
},
},
{{#if (eq payments "polar")}}
plugins: [
polar({
client: polarClient,
createCustomerOnSignUp: true,
enableCustomerPortal: true,
use: [
checkout({
products: [
{
productId: "your-product-id",
slug: "pro",
},
],
successUrl: process.env.POLAR_SUCCESS_URL,
authenticatedUsersOnly: true,
}),
portal(),
],
}),
{{#if (or (includes frontend "native-nativewind") (includes frontend "native-unistyles"))}}
expo(),
{{/if}}
],
{{else}}
{{#if (or (includes frontend "native-nativewind") (includes frontend "native-unistyles"))}}
plugins: [expo()],
{{/if}}
{{/if}}
});
{{/if}}
@@ -80,6 +140,10 @@ import { drizzleAdapter } from "better-auth/adapters/drizzle";
{{#if (or (includes frontend "native-nativewind") (includes frontend "native-unistyles"))}}
import { expo } from "@better-auth/expo";
{{/if}}
{{#if (eq payments "polar")}}
import { polar, checkout, portal } from "@polar-sh/better-auth";
import { polarClient } from "./payments";
{{/if}}
import { db } from "../db";
import * as schema from "../db/schema/auth";
import { env } from "cloudflare:workers";
@@ -109,9 +173,32 @@ export const auth = betterAuth<BetterAuthOptions>({
httpOnly: true,
},
},
{{#if (eq payments "polar")}}
plugins: [
polar({
client: polarClient,
createCustomerOnSignUp: true,
enableCustomerPortal: true,
use: [
checkout({
products: [
{
productId: "your-product-id",
slug: "pro",
},
],
successUrl: env.POLAR_SUCCESS_URL,
authenticatedUsersOnly: true,
}),
portal(),
],
}),
],
{{else}}
{{#if (or (includes frontend "native-nativewind") (includes frontend "native-unistyles"))}}
plugins: [expo()],
{{/if}}
{{/if}}
});
{{/if}}
{{/if}}
@@ -122,6 +209,10 @@ import { mongodbAdapter } from "better-auth/adapters/mongodb";
{{#if (or (includes frontend "native-nativewind") (includes frontend "native-unistyles"))}}
import { expo } from "@better-auth/expo";
{{/if}}
{{#if (eq payments "polar")}}
import { polar, checkout, portal } from "@polar-sh/better-auth";
import { polarClient } from "./payments";
{{/if}}
import { client } from "../db";
export const auth = betterAuth<BetterAuthOptions>({
@@ -141,9 +232,35 @@ export const auth = betterAuth<BetterAuthOptions>({
secure: true,
httpOnly: true,
},
}
},
{{#if (eq payments "polar")}}
plugins: [
polar({
client: polarClient,
createCustomerOnSignUp: true,
enableCustomerPortal: true,
use: [
checkout({
products: [
{
productId: "your-product-id",
slug: "pro",
},
],
successUrl: process.env.POLAR_SUCCESS_URL,
authenticatedUsersOnly: true,
}),
portal(),
],
}),
{{#if (or (includes frontend "native-nativewind") (includes frontend "native-unistyles"))}}
expo(),
{{/if}}
],
{{else}}
{{#if (or (includes frontend "native-nativewind") (includes frontend "native-unistyles"))}}
, plugins: [expo()]
plugins: [expo()],
{{/if}}
{{/if}}
});
{{/if}}
@@ -153,6 +270,10 @@ import { betterAuth, type BetterAuthOptions } from "better-auth";
{{#if (or (includes frontend "native-nativewind") (includes frontend "native-unistyles"))}}
import { expo } from "@better-auth/expo";
{{/if}}
{{#if (eq payments "polar")}}
import { polar, checkout, portal } from "@polar-sh/better-auth";
import { polarClient } from "./payments";
{{/if}}
export const auth = betterAuth<BetterAuthOptions>({
database: "", // Invalid configuration
@@ -171,9 +292,35 @@ export const auth = betterAuth<BetterAuthOptions>({
secure: true,
httpOnly: true,
},
}
},
{{#if (eq payments "polar")}}
plugins: [
polar({
client: polarClient,
createCustomerOnSignUp: true,
enableCustomerPortal: true,
use: [
checkout({
products: [
{
productId: "your-product-id",
slug: "pro",
},
],
successUrl: process.env.POLAR_SUCCESS_URL,
authenticatedUsersOnly: true,
}),
portal(),
],
}),
{{#if (or (includes frontend "native-nativewind") (includes frontend "native-unistyles"))}}
expo(),
{{/if}}
],
{{else}}
{{#if (or (includes frontend "native-nativewind") (includes frontend "native-unistyles"))}}
, plugins: [expo()]
plugins: [expo()],
{{/if}}
{{/if}}
});
{{/if}}