11// TODO: Extract shared auth config to packages/auth to avoid duplication with web/src/app/api/auth/[...nextauth]/auth-options.ts
22import { DrizzleAdapter } from '@auth/drizzle-adapter'
3- import { processAndGrantCredit } from '@codebuff/billing'
43import { trackEvent } from '@codebuff/common/analytics'
54import { 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'
126import { loops } from '@codebuff/internal'
137import db from '@codebuff/internal/db'
148import * as schema from '@codebuff/internal/db/schema'
@@ -18,7 +12,6 @@ import { logSyncFailure } from '@codebuff/internal/util/sync-failure'
1812import { eq } from 'drizzle-orm'
1913import GitHubProvider from 'next-auth/providers/github'
2014
21- import type { Logger } from '@codebuff/common/types/contracts/logger'
2215import type { NextAuthOptions } from 'next-auth'
2316import 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-
12874export 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 ,
0 commit comments