@@ -9,10 +9,11 @@ import {
99 handleUnsuccessfulApiResponse
1010} from '../utils/api-helpers'
1111import { printFlagList } from '../utils/formatting'
12- import { FREE_API_KEY , getDefaultKey , setupSdk } from '../utils/sdk'
12+ import { getDefaultKey , setupSdk } from '../utils/sdk'
1313
1414import type { CliSubcommand } from '../utils/meow-with-subcommands'
1515import type { Ora } from 'ora'
16+ import { AuthError } from '../utils/errors'
1617
1718export const auditLog : CliSubcommand = {
1819 description : 'Look up the audit log for an organization' ,
@@ -21,8 +22,12 @@ export const auditLog: CliSubcommand = {
2122
2223 const input = setupCommand ( name , auditLog . description , argv , importMeta )
2324 if ( input ) {
25+ const apiKey = getDefaultKey ( )
26+ if ( ! apiKey ) {
27+ throw new AuthError ( "User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key." )
28+ }
2429 const spinner = ora ( `Looking up audit log for ${ input . orgSlug } \n` ) . start ( )
25- await fetchOrgAuditLog ( input . orgSlug , input , spinner )
30+ await fetchOrgAuditLog ( input . orgSlug , input , spinner , apiKey )
2631 }
2732 }
2833}
@@ -132,9 +137,10 @@ type AuditChoices = (Separator | AuditChoice)[]
132137async function fetchOrgAuditLog (
133138 orgSlug : string ,
134139 input : CommandContext ,
135- spinner : Ora
140+ spinner : Ora ,
141+ apiKey : string
136142) : Promise < void > {
137- const socketSdk = await setupSdk ( getDefaultKey ( ) || FREE_API_KEY )
143+ const socketSdk = await setupSdk ( apiKey )
138144 const result = await handleApiCall (
139145 socketSdk . getAuditLogEvents ( orgSlug , input ) ,
140146 `Looking up audit log for ${ orgSlug } \n`
0 commit comments