Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

feat(core): support lifetime subscription from external link (#7585)

CatsJuicecb0d91facd91
diff --git a/packages/frontend/core/src/pages/subscribe.tsx b/packages/frontend/core/src/pages/subscribe.tsx
index 280a01cf53..9ee125a41d 100644
--- a/packages/frontend/core/src/pages/subscribe.tsx
+++ b/packages/frontend/core/src/pages/subscribe.tsx
@@ -28,6 +28,20 @@ export const Component = () => {
const recurring = searchParams.get('recurring') as string | null;
useEffect(() => {
+ const allowedPlan = ['ai', 'pro'];
+ const allowedRecurring = ['monthly', 'yearly', 'lifetime'];
+ const receivedPlan = plan?.toLowerCase() ?? '';
+ const receivedRecurring = recurring?.toLowerCase() ?? '';
+
+ const invalids = [];
+ if (!allowedPlan.includes(receivedPlan)) invalids.push('plan');
+ if (!allowedRecurring.includes(receivedRecurring))
+ invalids.push('recurring');
+ if (invalids.length) {
+ setError(`Invalid ${invalids.join(', ')}`);
+ return;
+ }
+
const call = effect(
switchMap(() => {
return fromPromise(async signal => {
@@ -49,9 +63,11 @@ export const Component = () => {
setMessage('Checking subscription status...');
await subscriptionService.subscription.waitForRevalidation(signal);
const subscribed =
- plan?.toLowerCase() === 'ai'
+ receivedPlan === 'ai'
? !!subscriptionService.subscription.ai$.value
- : !!subscriptionService.subscription.pro$.value;
+ : receivedRecurring === 'lifetime'
+ ? !!subscriptionService.subscription.isBeliever$.value
+ : !!subscriptionService.subscription.pro$.value;
if (!subscribed) {
setMessage('Creating checkout...');
mixpanel.track('PlanUpgradeStarted', {
@@ -63,13 +79,15 @@ export const Component = () => {
// should never reach
if (!account) throw new Error('No account');
const targetPlan =
- plan?.toLowerCase() === 'ai'
+ receivedPlan === 'ai'
? SubscriptionPlan.AI
: SubscriptionPlan.Pro;
const targetRecurring =
- recurring?.toLowerCase() === 'monthly'
+ receivedRecurring === 'monthly'
? SubscriptionRecurring.Monthly
- : SubscriptionRecurring.Yearly;
+ : receivedRecurring === 'yearly'
+ ? SubscriptionRecurring.Yearly
+ : SubscriptionRecurring.Lifetime;
const checkout = await subscriptionService.createCheckoutSession({
idempotencyKey,
plan: targetPlan,