diff --git a/lib/session/create.ts b/lib/session/create.ts index fa5d31c4..d4010d61 100644 --- a/lib/session/create.ts +++ b/lib/session/create.ts @@ -3,24 +3,19 @@ import 'server-only' import type { Session, Tokens } from './types' import { SESSION_COOKIE_NAME } from './constants' import { encryptJWE } from '@/lib/jwe/encrypt' -import { fetchTeams } from '@/lib/vercel-client/teams' import { fetchUser } from '@/lib/vercel-client/user' -import { getHighestAccountLevel } from '@/lib/vercel-client/utils' import { upsertUser } from '@/lib/db/users' import { encrypt } from '@/lib/crypto' import ms from 'ms' export async function createSession(tokens: Tokens): Promise { - const [user, teams] = await Promise.all([fetchUser(tokens.accessToken), fetchTeams(tokens.accessToken)]) + const user = await fetchUser(tokens.accessToken); if (!user) { console.log('Failed to fetch user') return undefined } - // Teams may fail due to permissions - default to hobby plan if unavailable - const plan = teams ? getHighestAccountLevel(teams) : { plan: 'hobby' as const, team: null } - // Create or update user in database const externalId = user.uid || user.id || '' const userId = await upsertUser({ diff --git a/lib/vercel-client/types.ts b/lib/vercel-client/types.ts index 4d6e78c8..5a02e872 100644 --- a/lib/vercel-client/types.ts +++ b/lib/vercel-client/types.ts @@ -9,28 +9,9 @@ export interface VercelUser { export interface VercelTeam { avatar?: string - billing?: Billing created?: string id: string name: string saml?: { enforced: boolean } slug: string } - -export type BillingPlan = 'hobby' | 'pro' | 'enterprise' - -type BillingStatus = 'active' | 'trialing' | 'overdue' | 'canceled' | 'expired' - -interface Billing { - addons?: string | null - email?: string - language?: string | null - name?: string | null - overdue?: boolean | null - period: { start: number; end: number } | null - plan: BillingPlan - platform?: 'stripe' | 'stripeTestMode' - purchaseOrder?: string | null - status?: BillingStatus - trial: { start: number; end: number } | null -} diff --git a/lib/vercel-client/utils.ts b/lib/vercel-client/utils.ts deleted file mode 100644 index 90535996..00000000 --- a/lib/vercel-client/utils.ts +++ /dev/null @@ -1,41 +0,0 @@ -import type { VercelTeam, BillingPlan } from './types' - -interface PlanInfo { - plan: BillingPlan - team: VercelTeam | null -} - -/** - * Find the team listed in the user teams with the highest account level - * that is currently active. - */ -export function getHighestAccountLevel(allTeams: VercelTeam[]): PlanInfo { - let highest: PlanInfo = { - plan: 'hobby', - team: null, - } - - if (!allTeams?.length) { - return highest - } - - const activeTeams = allTeams.filter((team) => team.billing?.plan && team.billing.status === 'active') - - for (const team of activeTeams) { - if (team.billing?.plan === 'enterprise') { - return { - plan: 'enterprise', - team, - } - } - - if (team.billing?.plan === 'pro') { - highest = { - plan: 'pro', - team, - } - } - } - - return highest -}