Load subscription data from API before rendering replay and heatmap views
This commit is contained in:
1 parent
385088d53a
commit
adba113b04
7 files changed
+111
-68
No files matched your search
@@ -1,4 +1,3 @@
|
||||
import { fetchAccount, fetchTeam } from '@/lib/load';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { json } from '@/lib/response';
|
||||
import { getAllUserTeams } from '@/queries/prisma';
|
||||
@@ -10,42 +9,7 @@ export async function POST(request: Request) {
|
||||
return error();
|
||||
}
|
||||
|
||||
const user = { ...auth.user };
|
||||
const teams = await getAllUserTeams(user.id);
|
||||
const teams = await getAllUserTeams(auth.user.id);
|
||||
|
||||
if (process.env.CLOUD_MODE) {
|
||||
const account = await fetchAccount(user.id);
|
||||
|
||||
if (account) {
|
||||
user.subscription = {
|
||||
isPro: account.isPro || false,
|
||||
isBusiness: account.isBusiness || false,
|
||||
isNoBilling: account.isNoBilling || false,
|
||||
hasSubscription: account.hasSubscription || false,
|
||||
unlimitedWebsites: account.unlimitedWebsites || false,
|
||||
};
|
||||
}
|
||||
|
||||
const teamsWithSubscription = await Promise.all(
|
||||
teams.map(async (team: any) => {
|
||||
const teamAccount = await fetchTeam(team.id);
|
||||
return {
|
||||
...team,
|
||||
subscription: teamAccount
|
||||
? {
|
||||
isPro: teamAccount.isPro || false,
|
||||
isBusiness: teamAccount.isBusiness || false,
|
||||
isNoBilling: teamAccount.isNoBilling || false,
|
||||
hasSubscription: teamAccount.hasSubscription || false,
|
||||
unlimitedWebsites: teamAccount.unlimitedWebsites || false,
|
||||
}
|
||||
: null,
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
return json({ ...user, teams: teamsWithSubscription });
|
||||
}
|
||||
|
||||
return json({ ...user, teams });
|
||||
return json({ ...auth.user, teams });
|
||||
}
|
||||
Reference in new issue
Block a user