Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

create team key in cloud mode

Francis Cao5461a512986f
diff --git a/src/app/api/teams/route.ts b/src/app/api/teams/route.ts
index c571f4055..2e2424a2f 100644
--- a/src/app/api/teams/route.ts
+++ b/src/app/api/teams/route.ts
@@ -1,6 +1,8 @@
import { z } from 'zod';
import { uuid } from '@/lib/crypto';
import { getRandomChars } from '@/lib/generate';
+import { fetchAccount } from '@/lib/load';
+import redis from '@/lib/redis';
import { getQueryFilters, parseRequest } from '@/lib/request';
import { json, unauthorized } from '@/lib/response';
import { pagingParams } from '@/lib/schema';
@@ -43,14 +45,35 @@ export async function POST(request: Request) {
const { name, ownerId } = body;
+ const teamId = uuid();
+ const teamOwnerId = ownerId ?? auth.user.id;
+
const team = await createTeam(
{
- id: uuid(),
+ id: teamId,
name,
accessCode: `team_${getRandomChars(16)}`,
},
- ownerId ?? auth.user.id,
+ teamOwnerId,
);
+ if (process.env.CLOUD_MODE && redis.enabled) {
+ const account = await fetchAccount(teamOwnerId);
+
+ if (account) {
+ await redis.client.set(
+ `team:${teamId}`,
+ {
+ teamOwnerId,
+ isPro: account.isPro || false,
+ isBusiness: account.isBusiness || false,
+ isNoBilling: account.isNoBilling || false,
+ hasSubscription: account.hasSubscription || false,
+ },
+ 60 * 60 * 24 * 90,
+ );
+ }
+ }
+
return json(team);
}