Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions lib/session/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Session | undefined> {
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({
Expand Down
19 changes: 0 additions & 19 deletions lib/vercel-client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
41 changes: 0 additions & 41 deletions lib/vercel-client/utils.ts

This file was deleted.