Skip to content

Commit 5b92516

Browse files
committed
Remove free credits for new accounts
1 parent 2e34fc1 commit 5b92516

File tree

2 files changed

+6
-127
lines changed

2 files changed

+6
-127
lines changed

freebuff/web/src/app/api/auth/[...nextauth]/auth-options.ts

Lines changed: 3 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
// TODO: Extract shared auth config to packages/auth to avoid duplication with web/src/app/api/auth/[...nextauth]/auth-options.ts
22
import { DrizzleAdapter } from '@auth/drizzle-adapter'
3-
import { processAndGrantCredit } from '@codebuff/billing'
43
import { trackEvent } from '@codebuff/common/analytics'
54
import { AnalyticsEvent } from '@codebuff/common/constants/analytics-events'
6-
import {
7-
DEFAULT_FREE_CREDITS_GRANT,
8-
SESSION_MAX_AGE_SECONDS,
9-
} from '@codebuff/common/old-constants'
10-
import { getNextQuotaReset } from '@codebuff/common/util/dates'
11-
import { generateCompactId } from '@codebuff/common/util/string'
5+
import { SESSION_MAX_AGE_SECONDS } from '@codebuff/common/old-constants'
126
import { loops } from '@codebuff/internal'
137
import db from '@codebuff/internal/db'
148
import * as schema from '@codebuff/internal/db/schema'
@@ -18,7 +12,6 @@ import { logSyncFailure } from '@codebuff/internal/util/sync-failure'
1812
import { eq } from 'drizzle-orm'
1913
import GitHubProvider from 'next-auth/providers/github'
2014

21-
import type { Logger } from '@codebuff/common/types/contracts/logger'
2215
import type { NextAuthOptions } from 'next-auth'
2316
import type { Adapter } from 'next-auth/adapters'
2417

@@ -78,53 +71,6 @@ async function createAndLinkStripeCustomer(params: {
7871
}
7972
}
8073

81-
async function createInitialCreditGrant(params: {
82-
userId: string
83-
expiresAt: Date | null
84-
logger: Logger
85-
}): Promise<void> {
86-
const { userId, expiresAt, logger } = params
87-
88-
try {
89-
const operationId = `free-${userId}-${generateCompactId()}`
90-
const nextQuotaReset = getNextQuotaReset(expiresAt)
91-
92-
await processAndGrantCredit({
93-
...params,
94-
amount: DEFAULT_FREE_CREDITS_GRANT,
95-
type: 'free',
96-
description: 'Initial free credits',
97-
expiresAt: nextQuotaReset,
98-
operationId,
99-
})
100-
101-
logger.info(
102-
{
103-
userId,
104-
operationId,
105-
creditsGranted: DEFAULT_FREE_CREDITS_GRANT,
106-
expiresAt: nextQuotaReset,
107-
},
108-
'Initial free credit grant created.',
109-
)
110-
} catch (grantError) {
111-
const errorMessage =
112-
grantError instanceof Error
113-
? grantError.message
114-
: 'Unknown error creating initial credit grant'
115-
logger.error(
116-
{ userId, error: grantError },
117-
'Failed to create initial credit grant.',
118-
)
119-
await logSyncFailure({
120-
id: userId,
121-
errorMessage,
122-
provider: 'stripe',
123-
logger,
124-
})
125-
}
126-
}
127-
12874
export const authOptions: NextAuthOptions = {
12975
adapter: DrizzleAdapter(db, {
13076
usersTable: schema.user,
@@ -194,18 +140,12 @@ export const authOptions: NextAuthOptions = {
194140
return
195141
}
196142

197-
const customerId = await createAndLinkStripeCustomer({
143+
await createAndLinkStripeCustomer({
198144
...userData,
199145
userId: userData.id,
200146
})
201147

202-
if (customerId) {
203-
await createInitialCreditGrant({
204-
userId: userData.id,
205-
expiresAt: userData.next_quota_reset,
206-
logger,
207-
})
208-
}
148+
// Freebuff is free - new accounts do not receive any credit grant.
209149

210150
await loops.sendSignupEventToLoops({
211151
...userData,

web/src/app/api/auth/[...nextauth]/auth-options.ts

Lines changed: 3 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import { DrizzleAdapter } from '@auth/drizzle-adapter'
2-
import { processAndGrantCredit } from '@codebuff/billing'
32
import { trackEvent } from '@codebuff/common/analytics'
43
import { AnalyticsEvent } from '@codebuff/common/constants/analytics-events'
5-
import {
6-
DEFAULT_FREE_CREDITS_GRANT,
7-
SESSION_MAX_AGE_SECONDS,
8-
} from '@codebuff/common/old-constants'
9-
import { getNextQuotaReset } from '@codebuff/common/util/dates'
10-
import { generateCompactId } from '@codebuff/common/util/string'
4+
import { SESSION_MAX_AGE_SECONDS } from '@codebuff/common/old-constants'
115
import { loops } from '@codebuff/internal'
126
import db from '@codebuff/internal/db'
137
import * as schema from '@codebuff/internal/db/schema'
@@ -17,7 +11,6 @@ import { logSyncFailure } from '@codebuff/internal/util/sync-failure'
1711
import { eq } from 'drizzle-orm'
1812
import GitHubProvider from 'next-auth/providers/github'
1913

20-
import type { Logger } from '@codebuff/common/types/contracts/logger'
2114
import type { NextAuthOptions } from 'next-auth'
2215
import type { Adapter } from 'next-auth/adapters'
2316

@@ -77,53 +70,6 @@ async function createAndLinkStripeCustomer(params: {
7770
}
7871
}
7972

80-
async function createInitialCreditGrant(params: {
81-
userId: string
82-
expiresAt: Date | null
83-
logger: Logger
84-
}): Promise<void> {
85-
const { userId, expiresAt, logger } = params
86-
87-
try {
88-
const operationId = `free-${userId}-${generateCompactId()}`
89-
const nextQuotaReset = getNextQuotaReset(expiresAt)
90-
91-
await processAndGrantCredit({
92-
...params,
93-
amount: DEFAULT_FREE_CREDITS_GRANT,
94-
type: 'free',
95-
description: 'Initial free credits',
96-
expiresAt: nextQuotaReset,
97-
operationId,
98-
})
99-
100-
logger.info(
101-
{
102-
userId,
103-
operationId,
104-
creditsGranted: DEFAULT_FREE_CREDITS_GRANT,
105-
expiresAt: nextQuotaReset,
106-
},
107-
'Initial free credit grant created.',
108-
)
109-
} catch (grantError) {
110-
const errorMessage =
111-
grantError instanceof Error
112-
? grantError.message
113-
: 'Unknown error creating initial credit grant'
114-
logger.error(
115-
{ userId, error: grantError },
116-
'Failed to create initial credit grant.',
117-
)
118-
await logSyncFailure({
119-
id: userId,
120-
errorMessage,
121-
provider: 'stripe',
122-
logger,
123-
})
124-
}
125-
}
126-
12773
export const authOptions: NextAuthOptions = {
12874
adapter: DrizzleAdapter(db, {
12975
usersTable: schema.user,
@@ -206,20 +152,13 @@ export const authOptions: NextAuthOptions = {
206152
return
207153
}
208154

209-
const customerId = await createAndLinkStripeCustomer({
155+
await createAndLinkStripeCustomer({
210156
...userData,
211157
userId: userData.id,
212158
})
213159

214-
if (customerId) {
215-
await createInitialCreditGrant({
216-
userId: userData.id,
217-
expiresAt: userData.next_quota_reset,
218-
logger,
219-
})
220-
}
160+
// New codebuff accounts do not receive a signup bonus.
221161

222-
// Call the imported function
223162
await loops.sendSignupEventToLoops({
224163
...userData,
225164
userId: userData.id,

0 commit comments

Comments
 (0)