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.

fix(server): standalone early access users detection (#5601)

liuyi75fb0a9f1a3b
diff --git a/packages/backend/server/src/modules/features/management.ts b/packages/backend/server/src/modules/features/management.ts
index 75f11ba1e3..dfccaa8919 100644
--- a/packages/backend/server/src/modules/features/management.ts
+++ b/packages/backend/server/src/modules/features/management.ts
@@ -47,22 +47,26 @@ export class FeatureManagementService {
return this.feature.listFeatureUsers(FeatureType.EarlyAccess);
}
+ async isEarlyAccessUser(email: string) {
+ const user = await this.prisma.user.findFirst({
+ where: {
+ email,
+ },
+ });
+ if (user) {
+ const canEarlyAccess = await this.feature
+ .hasUserFeature(user.id, FeatureType.EarlyAccess)
+ .catch(() => false);
+
+ return canEarlyAccess;
+ }
+ return false;
+ }
+
/// check early access by email
async canEarlyAccess(email: string) {
if (this.config.featureFlags.earlyAccessPreview && !this.isStaff(email)) {
- const user = await this.prisma.user.findFirst({
- where: {
- email,
- },
- });
- if (user) {
- const canEarlyAccess = await this.feature
- .hasUserFeature(user.id, FeatureType.EarlyAccess)
- .catch(() => false);
-
- return canEarlyAccess;
- }
- return false;
+ return this.isEarlyAccessUser(email);
} else {
return true;
}
diff --git a/packages/backend/server/src/modules/payment/service.ts b/packages/backend/server/src/modules/payment/service.ts
index 137c3585bd..8c40c360df 100644
--- a/packages/backend/server/src/modules/payment/service.ts
+++ b/packages/backend/server/src/modules/payment/service.ts
@@ -679,7 +679,7 @@ export class SubscriptionService {
user: User,
couponType: CouponType
): Promise<string | null> {
- const earlyAccess = await this.features.canEarlyAccess(user.email);
+ const earlyAccess = await this.features.isEarlyAccessUser(user.email);
if (earlyAccess) {
try {
const coupon = await this.stripe.coupons.retrieve(couponType);