📨 The ultimate agentic social media scheduling tool 🤖
TypeScript nextjsopen-sourceopen-source-social-media-scheduling-toolosspostiz-cloudpostiz-hostedredisscheduling-toolsocial-media-scheduling-tooltypescript
feat: block subscribing when a same-email account is already subscribed
Gilad Resisi9d0919f85184
diff --git a/apps/backend/src/api/routes/billing.controller.ts b/apps/backend/src/api/routes/billing.controller.tsindex dd6686b15..b09fb414a 100644--- a/apps/backend/src/api/routes/billing.controller.ts+++ b/apps/backend/src/api/routes/billing.controller.ts@@ -9,6 +9,7 @@ import { GetUserFromRequest } from '@gitroom/nestjs-libraries/user/user.from.reqimport { NotificationService } from '@gitroom/nestjs-libraries/database/prisma/notifications/notification.service';import { Request } from 'express';import { AuthService } from '@gitroom/helpers/auth/auth.service';+import { UsersService } from '@gitroom/nestjs-libraries/database/prisma/users/users.service';@ApiTags('Billing')@Controller('/billing')@@ -16,9 +17,18 @@ export class BillingController {constructor(private _subscriptionService: SubscriptionService,private _stripeService: StripeService,- private _notificationService: NotificationService+ private _notificationService: NotificationService,+ private _usersService: UsersService) {}+ private async assertNoOtherSubscribedAccount(user: User) {+ const other = await this._usersService.getUserWithActiveSubscriptionByEmail(+ user.email,+ user.id+ );+ return !!other;+ }+@Get('/check/:id')async checkId(@GetOrgFromRequest() org: Organization,@@ -61,12 +71,16 @@ export class BillingController {}@Post('/embedded')- embedded(+ async embedded(@GetOrgFromRequest() org: Organization,@GetUserFromRequest() user: User,@Body() body: BillingSubscribeDto,@Req() req: Request) {+ if (await this.assertNoOtherSubscribedAccount(user)) {+ return { blocked: true };+ }+const uniqueId = req?.cookies?.track;return this._stripeService.embedded(uniqueId,@@ -78,12 +92,16 @@ export class BillingController {}@Post('/subscribe')- subscribe(+ async subscribe(@GetOrgFromRequest() org: Organization,@GetUserFromRequest() user: User,@Body() body: BillingSubscribeDto,@Req() req: Request) {+ if (await this.assertNoOtherSubscribedAccount(user)) {+ return { blocked: true };+ }+const uniqueId = req?.cookies?.track;return this._stripeService.subscribe(uniqueId,diff --git a/apps/frontend/src/components/billing/first.billing.component.tsx b/apps/frontend/src/components/billing/first.billing.component.tsxindex 96a9e7ecc..ee8d8b165 100644--- a/apps/frontend/src/components/billing/first.billing.component.tsx+++ b/apps/frontend/src/components/billing/first.billing.component.tsx@@ -205,7 +205,14 @@ export const FirstBillingComponent = () => {<div className="block tablet:hidden"><JoinOver /></div>- {!isLoading && data && stripe ? (+ {data?.blocked ? (+ <div className="mt-[24px] p-[24px] rounded-[20px] border-[1.5px] border-newColColor text-[16px] font-[500]">+ {t(+ 'billing_other_account_subscribed',+ 'Another account with this email already has an active subscription. Please log off and sign in to that account to manage your subscription.'+ )}+ </div>+ ) : !isLoading && data && stripe ? (<EmbeddedBillingstripe={stripe}secret={data.client_secret}diff --git a/apps/frontend/src/components/billing/main.billing.component.tsx b/apps/frontend/src/components/billing/main.billing.component.tsxindex 1d8d05b6b..523e442b8 100644--- a/apps/frontend/src/components/billing/main.billing.component.tsx+++ b/apps/frontend/src/components/billing/main.billing.component.tsx@@ -379,7 +379,7 @@ export const MainBillingComponent: FC<{return;}setLoading(true);- const { url, portal } = await (+ const { url, portal, blocked } = await (await fetch('/billing/subscribe', {method: 'POST',body: JSON.stringify({@@ -390,6 +390,18 @@ export const MainBillingComponent: FC<{}),})).json();+ if (blocked) {+ setLoading(false);+ await deleteDialog(+ t(+ 'billing_other_account_subscribed',+ 'Another account with this email already has an active subscription. Please log off and sign in to that account to manage your subscription.'+ ),+ t('ok', 'OK'),+ t('already_subscribed', 'Already subscribed')+ );+ return;+ }if (url) {await track(TrackEnum.InitiateCheckout, {value:diff --git a/i18n.lock b/i18n.lockindex aae333cc7..814498783 100644--- a/i18n.lock+++ b/i18n.lock@@ -508,6 +508,9 @@ checksums:label_who_can_reply_to_this_post: 4d8913296a1fc3f197cb0aead34af73ddelete_integration: ccc879ccfcf7f85bcfe09f2bc3fa0dd3start_writing_your_post: 471efc4f2a7e2cf02a065a2de34e7213+ billing_other_account_subscribed: 6c12b4a726d55ee88b0594bd22ec556c+ already_subscribed: 3694e02bcb0a41286ea6b79615e6cdbf+ ok: e2d6579a83aba07c4180c21c5fe9893dbilling_join_over: 6e1c237241ba00ddbb07fd603344c5c3billing_entrepreneurs_count: 1e90206cb8ea01d0a1084d3af1a4cbedbilling_who_use: 63bdc59ef443e193eca87889e83ea07adiff --git a/libraries/nestjs-libraries/src/database/prisma/users/users.repository.ts b/libraries/nestjs-libraries/src/database/prisma/users/users.repository.tsindex 38a03c761..679b4bf5c 100644--- a/libraries/nestjs-libraries/src/database/prisma/users/users.repository.ts+++ b/libraries/nestjs-libraries/src/database/prisma/users/users.repository.ts@@ -1,6 +1,6 @@import { PrismaRepository } from '@gitroom/nestjs-libraries/database/prisma/prisma.service';import { Injectable } from '@nestjs/common';-import { Provider } from '@prisma/client';+import { Provider, Role } from '@prisma/client';import { AuthService } from '@gitroom/helpers/auth/auth.service';import { UserDetailDto } from '@gitroom/nestjs-libraries/dtos/users/user.details.dto';import { EmailNotificationsDto } from '@gitroom/nestjs-libraries/dtos/users/email-notifications.dto';@@ -64,6 +64,24 @@ export class UsersRepository {});}+ getUserWithActiveSubscriptionByEmail(email: string, excludeUserId: string) {+ return this._user.model.user.findFirst({+ where: {+ email,+ id: { not: excludeUserId },+ organizations: {+ some: {+ role: Role.SUPERADMIN,+ organization: {+ subscription: { is: { deletedAt: null } },+ },+ },+ },+ },+ select: { id: true, email: true, providerName: true },+ });+ }+activateUser(id: string) {return this._user.model.user.update({where: {diff --git a/libraries/nestjs-libraries/src/database/prisma/users/users.service.ts b/libraries/nestjs-libraries/src/database/prisma/users/users.service.tsindex 863949cbc..28a8c449b 100644--- a/libraries/nestjs-libraries/src/database/prisma/users/users.service.ts+++ b/libraries/nestjs-libraries/src/database/prisma/users/users.service.ts@@ -20,6 +20,13 @@ export class UsersService {return this._usersRepository.getUserById(id);}+ getUserWithActiveSubscriptionByEmail(email: string, excludeUserId: string) {+ return this._usersRepository.getUserWithActiveSubscriptionByEmail(+ email,+ excludeUserId+ );+ }+getImpersonateUser(name: string) {return this._organizationRepository.getImpersonateUser(name);}diff --git a/libraries/react-shared-libraries/src/translation/locales/ar/translation.json b/libraries/react-shared-libraries/src/translation/locales/ar/translation.jsonindex 01bbb6b01..0dcea9485 100644--- a/libraries/react-shared-libraries/src/translation/locales/ar/translation.json+++ b/libraries/react-shared-libraries/src/translation/locales/ar/translation.json@@ -504,6 +504,9 @@"label_who_can_reply_to_this_post": "من يمكنه الرد على هذا المنشور؟","delete_integration": "حذف التكامل","start_writing_your_post": "ابدأ بكتابة منشورك لمعاينة",+ "billing_other_account_subscribed": "هناك حساب آخر يستخدم هذا البريد الإلكتروني لديه اشتراك نشط بالفعل. يرجى تسجيل الخروج وتسجيل الدخول إلى ذلك الحساب لإدارة اشتراكك.",+ "already_subscribed": "مشترك بالفعل",+ "ok": "موافق","billing_join_over": "انضم إلى أكثر من","billing_entrepreneurs_count": "أكثر من 20,000 رائد أعمال","billing_who_use": "الذين يستخدمون",diff --git a/libraries/react-shared-libraries/src/translation/locales/bn/translation.json b/libraries/react-shared-libraries/src/translation/locales/bn/translation.jsonindex db2c4d863..46c0a4a70 100644--- a/libraries/react-shared-libraries/src/translation/locales/bn/translation.json+++ b/libraries/react-shared-libraries/src/translation/locales/bn/translation.json@@ -504,6 +504,9 @@"label_who_can_reply_to_this_post": "এই পোস্টে কে উত্তর দিতে পারবে?","delete_integration": "ইন্টিগ্রেশন মুছে ফেলুন","start_writing_your_post": "প্রিভিউর জন্য আপনার পোস্ট লেখা শুরু করুন",+ "billing_other_account_subscribed": "এই ইমেইলটি ব্যবহার করে অন্য একটি অ্যাকাউন্টে ইতিমধ্যে সক্রিয় সাবস্ক্রিপশন রয়েছে। দয়া করে লগ আউট করুন এবং সাবস্ক্রিপশনটি পরিচালনা করতে ঐ অ্যাকাউন্টে সাইন ইন করুন।",+ "already_subscribed": "ইতিমধ্যে সাবস্ক্রাইব করা হয়েছে",+ "ok": "ঠিক আছে","billing_join_over": "যোগ দিন","billing_entrepreneurs_count": "২০,০০০+ উদ্যোক্তা","billing_who_use": "যারা ব্যবহার করেন",diff --git a/libraries/react-shared-libraries/src/translation/locales/de/translation.json b/libraries/react-shared-libraries/src/translation/locales/de/translation.jsonindex b38e9303e..483d0ece4 100644--- a/libraries/react-shared-libraries/src/translation/locales/de/translation.json+++ b/libraries/react-shared-libraries/src/translation/locales/de/translation.json@@ -504,6 +504,9 @@"label_who_can_reply_to_this_post": "Wer kann auf diesen Beitrag antworten?","delete_integration": "Integration löschen","start_writing_your_post": "Beginne, deinen Beitrag für eine Vorschau zu schreiben",+ "billing_other_account_subscribed": "Ein anderes Konto mit dieser E-Mail-Adresse hat bereits ein aktives Abonnement. Bitte melden Sie sich ab und melden Sie sich mit diesem Konto an, um Ihr Abonnement zu verwalten.",+ "already_subscribed": "Bereits abonniert",+ "ok": "OK","billing_join_over": "Schließen Sie sich über","billing_entrepreneurs_count": "20.000+ Unternehmer","billing_who_use": "die nutzen",diff --git a/libraries/react-shared-libraries/src/translation/locales/en/translation.json b/libraries/react-shared-libraries/src/translation/locales/en/translation.jsonindex 5d677f534..36522ebd1 100644--- a/libraries/react-shared-libraries/src/translation/locales/en/translation.json+++ b/libraries/react-shared-libraries/src/translation/locales/en/translation.json@@ -504,6 +504,9 @@"label_who_can_reply_to_this_post": "Who can reply to this post?","delete_integration": "Delete Integration","start_writing_your_post": "Start writing your post for a preview",+ "billing_other_account_subscribed": "Another account with this email already has an active subscription. Please log off and sign in to that account to manage your subscription.",+ "already_subscribed": "Already subscribed",+ "ok": "OK","billing_join_over": "Join Over","billing_entrepreneurs_count": "20,000+ Entrepreneurs","billing_who_use": "who use",diff --git a/libraries/react-shared-libraries/src/translation/locales/es/translation.json b/libraries/react-shared-libraries/src/translation/locales/es/translation.jsonindex 7e333a741..437fb3778 100644--- a/libraries/react-shared-libraries/src/translation/locales/es/translation.json+++ b/libraries/react-shared-libraries/src/translation/locales/es/translation.json@@ -504,6 +504,9 @@"label_who_can_reply_to_this_post": "¿Quién puede responder a esta publicación?","delete_integration": "Eliminar integración","start_writing_your_post": "Comienza a escribir tu publicación para obtener una vista previa",+ "billing_other_account_subscribed": "Otra cuenta con este correo electrónico ya tiene una suscripción activa. Por favor, cierra sesión e inicia sesión con esa cuenta para gestionar tu suscripción.",+ "already_subscribed": "Ya está suscrito",+ "ok": "OK","billing_join_over": "Únete a más de","billing_entrepreneurs_count": "Más de 20,000 emprendedores","billing_who_use": "que usan",diff --git a/libraries/react-shared-libraries/src/translation/locales/fr/translation.json b/libraries/react-shared-libraries/src/translation/locales/fr/translation.jsonindex cca906995..03a0882ee 100644--- a/libraries/react-shared-libraries/src/translation/locales/fr/translation.json+++ b/libraries/react-shared-libraries/src/translation/locales/fr/translation.json@@ -504,6 +504,9 @@"label_who_can_reply_to_this_post": "Qui peut répondre à ce post ?","delete_integration": "Supprimer l'intégration","start_writing_your_post": "Commencez à écrire votre post pour un aperçu",+ "billing_other_account_subscribed": "Un autre compte avec cet e-mail a déjà un abonnement actif. Veuillez vous déconnecter et vous connecter à ce compte pour gérer votre abonnement.",+ "already_subscribed": "Déjà abonné",+ "ok": "OK","billing_join_over": "Rejoignez plus de","billing_entrepreneurs_count": "Plus de 20 000 entrepreneurs","billing_who_use": "qui utilisent",diff --git a/libraries/react-shared-libraries/src/translation/locales/he/translation.json b/libraries/react-shared-libraries/src/translation/locales/he/translation.jsonindex 023da9162..03645eaac 100644--- a/libraries/react-shared-libraries/src/translation/locales/he/translation.json+++ b/libraries/react-shared-libraries/src/translation/locales/he/translation.json@@ -504,6 +504,9 @@"label_who_can_reply_to_this_post": "מי יכול להגיב לפוסט הזה?","delete_integration": "מחק אינטגרציה","start_writing_your_post": "התחל לכתוב את הפוסט שלך לתצוגה מקדימה",+ "billing_other_account_subscribed": "קיים חשבון אחר עם כתובת האימייל הזו שכבר יש לו מנוי פעיל. נא להתנתק ולהתחבר לחשבון הזה כדי לנהל את המנוי שלך.",+ "already_subscribed": "כבר רשום כמנוי",+ "ok": "אישור","billing_join_over": "הצטרפו ליותר מ-","billing_entrepreneurs_count": "20,000+ יזמים","billing_who_use": "שמשתמשים ב-",diff --git a/libraries/react-shared-libraries/src/translation/locales/it/translation.json b/libraries/react-shared-libraries/src/translation/locales/it/translation.jsonindex 088480a59..8e24b2ae3 100644--- a/libraries/react-shared-libraries/src/translation/locales/it/translation.json+++ b/libraries/react-shared-libraries/src/translation/locales/it/translation.json@@ -504,6 +504,9 @@"label_who_can_reply_to_this_post": "Chi può rispondere a questo post?","delete_integration": "Elimina integrazione","start_writing_your_post": "Inizia a scrivere il tuo post per un'anteprima",+ "billing_other_account_subscribed": "Un altro account con questa email ha già un abbonamento attivo. Disconnettiti e accedi a quell'account per gestire il tuo abbonamento.",+ "already_subscribed": "Già abbonato",+ "ok": "OK","billing_join_over": "Unisciti a oltre","billing_entrepreneurs_count": "Oltre 20.000 imprenditori","billing_who_use": "che usano",diff --git a/libraries/react-shared-libraries/src/translation/locales/ja/translation.json b/libraries/react-shared-libraries/src/translation/locales/ja/translation.jsonindex 522a791d8..e9b43059f 100644--- a/libraries/react-shared-libraries/src/translation/locales/ja/translation.json+++ b/libraries/react-shared-libraries/src/translation/locales/ja/translation.json@@ -504,6 +504,9 @@"label_who_can_reply_to_this_post": "この投稿に返信できる人","delete_integration": "連携を削除","start_writing_your_post": "プレビュー用に投稿を書き始めてください",+ "billing_other_account_subscribed": "このメールアドレスを持つ別のアカウントですでに有効なサブスクリプションがあります。サブスクリプションを管理するには、そのアカウントからサインアウトし、該当するアカウントでサインインしてください。",+ "already_subscribed": "すでに登録済みです",+ "ok": "OK","billing_join_over": "すでに参加している","billing_entrepreneurs_count": "20,000人以上の起業家","billing_who_use": "が利用している",diff --git a/libraries/react-shared-libraries/src/translation/locales/ko/translation.json b/libraries/react-shared-libraries/src/translation/locales/ko/translation.jsonindex ae2fb8e33..2ba16f985 100644--- a/libraries/react-shared-libraries/src/translation/locales/ko/translation.json+++ b/libraries/react-shared-libraries/src/translation/locales/ko/translation.json@@ -504,6 +504,9 @@"label_who_can_reply_to_this_post": "이 게시물에 누가 답글을 달 수 있나요?","delete_integration": "통합 삭제","start_writing_your_post": "미리보기를 위해 게시글 작성을 시작하세요",+ "billing_other_account_subscribed": "이 이메일로 이미 활성화된 구독이 있는 다른 계정이 있습니다. 구독을 관리하려면 로그아웃한 후 해당 계정으로 다시 로그인해 주세요.",+ "already_subscribed": "이미 구독됨",+ "ok": "확인","billing_join_over": "이미 가입한","billing_entrepreneurs_count": "20,000+명의 창업가","billing_who_use": "이(가) 사용하는",diff --git a/libraries/react-shared-libraries/src/translation/locales/pt/translation.json b/libraries/react-shared-libraries/src/translation/locales/pt/translation.jsonindex 09d4f08d3..e310a3d19 100644--- a/libraries/react-shared-libraries/src/translation/locales/pt/translation.json+++ b/libraries/react-shared-libraries/src/translation/locales/pt/translation.json@@ -504,6 +504,9 @@"label_who_can_reply_to_this_post": "Quem pode responder a esta postagem?","delete_integration": "Excluir integração","start_writing_your_post": "Comece a escrever sua postagem para visualizar",+ "billing_other_account_subscribed": "Outra conta com este e-mail já possui uma assinatura ativa. Por favor, faça logout e acesse essa conta para gerenciar sua assinatura.",+ "already_subscribed": "Já inscrito",+ "ok": "OK","billing_join_over": "Junte-se a mais de","billing_entrepreneurs_count": "20.000+ Empreendedores","billing_who_use": "que usam",diff --git a/libraries/react-shared-libraries/src/translation/locales/ru/translation.json b/libraries/react-shared-libraries/src/translation/locales/ru/translation.jsonindex 2e8ada903..e603fb400 100644--- a/libraries/react-shared-libraries/src/translation/locales/ru/translation.json+++ b/libraries/react-shared-libraries/src/translation/locales/ru/translation.json@@ -504,6 +504,9 @@"label_who_can_reply_to_this_post": "Кто может отвечать на этот пост?","delete_integration": "Удалить интеграцию","start_writing_your_post": "Начните писать свой пост для предварительного просмотра",+ "billing_other_account_subscribed": "Другой аккаунт с этим адресом электронной почты уже имеет активную подписку. Пожалуйста, выйдите из системы и войдите в этот аккаунт, чтобы управлять своей подпиской.",+ "already_subscribed": "Уже подписаны",+ "ok": "ОК","billing_join_over": "Присоединяйтесь к","billing_entrepreneurs_count": "20 000+ предпринимателей","billing_who_use": "которые используют",diff --git a/libraries/react-shared-libraries/src/translation/locales/tr/translation.json b/libraries/react-shared-libraries/src/translation/locales/tr/translation.jsonindex e7427120e..8174ee92d 100644--- a/libraries/react-shared-libraries/src/translation/locales/tr/translation.json+++ b/libraries/react-shared-libraries/src/translation/locales/tr/translation.json@@ -504,6 +504,9 @@"label_who_can_reply_to_this_post": "Bu gönderiye kim yanıt verebilir?","delete_integration": "Entegrasyonu Sil","start_writing_your_post": "Önizleme için gönderinizi yazmaya başlayın",+ "billing_other_account_subscribed": "Bu e-posta ile başka bir hesapta zaten aktif bir abonelik var. Aboneliğinizi yönetmek için lütfen çıkış yapıp o hesaba giriş yapın.",+ "already_subscribed": "Zaten abone olundu",+ "ok": "Tamam","billing_join_over": "Katılan","billing_entrepreneurs_count": "20.000+ Girişimci","billing_who_use": "kullanan",diff --git a/libraries/react-shared-libraries/src/translation/locales/vi/translation.json b/libraries/react-shared-libraries/src/translation/locales/vi/translation.jsonindex c04879605..2594880fd 100644--- a/libraries/react-shared-libraries/src/translation/locales/vi/translation.json+++ b/libraries/react-shared-libraries/src/translation/locales/vi/translation.json@@ -504,6 +504,9 @@"label_who_can_reply_to_this_post": "Ai có thể trả lời bài viết này?","delete_integration": "Xóa tích hợp","start_writing_your_post": "Bắt đầu viết bài của bạn để xem trước",+ "billing_other_account_subscribed": "Một tài khoản khác sử dụng email này đã có đăng ký đang hoạt động. Vui lòng đăng xuất và đăng nhập vào tài khoản đó để quản lý đăng ký của bạn.",+ "already_subscribed": "Đã đăng ký",+ "ok": "OK","billing_join_over": "Tham gia cùng hơn","billing_entrepreneurs_count": "Hơn 20.000 doanh nhân","billing_who_use": "đang sử dụng",diff --git a/libraries/react-shared-libraries/src/translation/locales/zh/translation.json b/libraries/react-shared-libraries/src/translation/locales/zh/translation.jsonindex 42a4c9b0f..9cdaa31e0 100644--- a/libraries/react-shared-libraries/src/translation/locales/zh/translation.json+++ b/libraries/react-shared-libraries/src/translation/locales/zh/translation.json@@ -504,6 +504,9 @@"label_who_can_reply_to_this_post": "谁可以回复此帖子?","delete_integration": "删除集成","start_writing_your_post": "开始写你的帖子以预览",+ "billing_other_account_subscribed": "此邮箱已关联其他账户并有有效订阅。请注销当前账户并使用该账户登录以管理您的订阅。",+ "already_subscribed": "已订阅",+ "ok": "确定","billing_join_over": "已有超过","billing_entrepreneurs_count": "20,000+ 位创业者","billing_who_use": "正在使用",