mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
feat(cli): add polar as better-auth plugin (#578)
This commit is contained in:
@@ -11,9 +11,28 @@ definePageMeta({
|
||||
const { $orpc } = useNuxtApp()
|
||||
|
||||
const session = $authClient.useSession()
|
||||
{{#if (eq payments "polar")}}
|
||||
const customerState = ref<any>(null)
|
||||
{{/if}}
|
||||
|
||||
{{#if (eq api "orpc")}}
|
||||
const privateData = useQuery($orpc.privateData.queryOptions())
|
||||
const privateData = useQuery({
|
||||
...$orpc.privateData.queryOptions(),
|
||||
enabled: computed(() => !!session.value?.data?.user)
|
||||
})
|
||||
{{/if}}
|
||||
|
||||
{{#if (eq payments "polar")}}
|
||||
onMounted(async () => {
|
||||
if (session.value?.data) {
|
||||
const { data } = await $authClient.customer.state()
|
||||
customerState.value = data
|
||||
}
|
||||
})
|
||||
|
||||
const hasProSubscription = computed(() =>
|
||||
customerState.value?.activeSubscriptions?.length! > 0
|
||||
)
|
||||
{{/if}}
|
||||
|
||||
</script>
|
||||
@@ -27,7 +46,22 @@ const privateData = useQuery($orpc.privateData.queryOptions())
|
||||
{{#if (eq api "orpc")}}
|
||||
<div v-if="privateData.status.value === 'pending'">Loading private data...</div>
|
||||
<div v-else-if="privateData.status.value === 'error'">Error loading private data: \{{ privateData.error.value?.message }}</div>
|
||||
<p v-else-if="privateData.data.value">Private Data: \{{ privateData.data.value.message }}</p>
|
||||
<p v-else-if="privateData.data.value">API: \{{ privateData.data.value.message }}</p>
|
||||
{{/if}}
|
||||
{{#if (eq payments "polar")}}
|
||||
<p class="mb-2">Plan: \{{ hasProSubscription ? "Pro" : "Free" }}</p>
|
||||
<UButton
|
||||
v-if="hasProSubscription"
|
||||
@click="() => { $authClient.customer.portal() }"
|
||||
>
|
||||
Manage Subscription
|
||||
</UButton>
|
||||
<UButton
|
||||
v-else
|
||||
@click="() => { $authClient.checkout({ slug: 'pro' }) }"
|
||||
>
|
||||
Upgrade to Pro
|
||||
</UButton>
|
||||
{{/if}}
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import { createAuthClient } from "better-auth/vue";
|
||||
|
||||
export default defineNuxtPlugin(nuxtApp => {
|
||||
const config = useRuntimeConfig()
|
||||
const serverUrl = config.public.serverURL
|
||||
|
||||
const authClient = createAuthClient({
|
||||
baseURL: serverUrl
|
||||
})
|
||||
|
||||
return {
|
||||
provide: {
|
||||
authClient: authClient
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,22 @@
|
||||
import { createAuthClient } from "better-auth/vue";
|
||||
{{#if (eq payments "polar")}}
|
||||
import { polarClient } from "@polar-sh/better-auth";
|
||||
{{/if}}
|
||||
|
||||
export default defineNuxtPlugin((nuxtApp) => {
|
||||
const config = useRuntimeConfig();
|
||||
const serverUrl = config.public.serverURL;
|
||||
|
||||
const authClient = createAuthClient({
|
||||
baseURL: serverUrl,
|
||||
{{#if (eq payments "polar")}}
|
||||
plugins: [polarClient()],
|
||||
{{/if}}
|
||||
});
|
||||
|
||||
return {
|
||||
provide: {
|
||||
authClient: authClient,
|
||||
},
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user