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(server): add pro quota to dev user (#6532)

EYHN9e7a2fcf0ec8
diff --git a/packages/backend/server/src/core/auth/index.ts b/packages/backend/server/src/core/auth/index.ts
index 318075f745..b840a5108c 100644
--- a/packages/backend/server/src/core/auth/index.ts
+++ b/packages/backend/server/src/core/auth/index.ts
@@ -1,6 +1,7 @@
import { Module } from '@nestjs/common';
import { FeatureModule } from '../features';
+import { QuotaModule } from '../quota';
import { UserModule } from '../user';
import { AuthController } from './controller';
import { AuthResolver } from './resolver';
@@ -8,7 +9,7 @@ import { AuthService } from './service';
import { TokenService, TokenType } from './token';
@Module({
- imports: [FeatureModule, UserModule],
+ imports: [FeatureModule, UserModule, QuotaModule],
providers: [AuthService, AuthResolver, TokenService],
exports: [AuthService],
controllers: [AuthController],
diff --git a/packages/backend/server/src/core/auth/service.ts b/packages/backend/server/src/core/auth/service.ts
index 86adf281b2..54021c6bcc 100644
--- a/packages/backend/server/src/core/auth/service.ts
+++ b/packages/backend/server/src/core/auth/service.ts
@@ -11,6 +11,8 @@ import { assign, omit } from 'lodash-es';
import { Config, CryptoHelper, MailService } from '../../fundamentals';
import { FeatureManagementService } from '../features/management';
+import { QuotaService } from '../quota/service';
+import { QuotaType } from '../quota/types';
import { UserService } from '../user/service';
import type { CurrentUser } from './current-user';
@@ -68,15 +70,21 @@ export class AuthService implements OnApplicationBootstrap {
private readonly db: PrismaClient,
private readonly mailer: MailService,
private readonly feature: FeatureManagementService,
+ private readonly quota: QuotaService,
private readonly user: UserService,
private readonly crypto: CryptoHelper
) {}
async onApplicationBootstrap() {
if (this.config.node.dev) {
- await this.signUp('Dev User', '[email protected]', 'dev').catch(() => {
+ try {
+ const devUser = await this.signUp('Dev User', '[email protected]', 'dev');
+ if (devUser) {
+ await this.quota.switchUserQuota(devUser?.id, QuotaType.ProPlanV1);
+ }
+ } catch (e) {
// ignore
- });
+ }
}
}
diff --git a/packages/backend/server/tests/auth/service.spec.ts b/packages/backend/server/tests/auth/service.spec.ts
index 55fbc24dd1..3d4db7b37f 100644
--- a/packages/backend/server/tests/auth/service.spec.ts
+++ b/packages/backend/server/tests/auth/service.spec.ts
@@ -5,6 +5,7 @@ import ava, { TestFn } from 'ava';
import { CurrentUser } from '../../src/core/auth';
import { AuthService, parseAuthUserSeqNum } from '../../src/core/auth/service';
import { FeatureModule } from '../../src/core/features';
+import { QuotaModule } from '../../src/core/quota';
import { UserModule, UserService } from '../../src/core/user';
import { createTestingModule } from '../utils';
@@ -18,7 +19,7 @@ const test = ava as TestFn<{
test.beforeEach(async t => {
const m = await createTestingModule({
- imports: [FeatureModule, UserModule],
+ imports: [QuotaModule, FeatureModule, UserModule],
providers: [AuthService],
});