Skip to content
Merged
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
6 changes: 2 additions & 4 deletions messages/logout.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ All orgs includes Dev Hubs, sandboxes, DE orgs, and expired, deleted, and unknow

# flags.client-app.summary

Client app to log out of.
Client app to log out of.

# logoutOrgCommandSuccess

Expand Down Expand Up @@ -98,8 +98,6 @@ You must specify a target-org (or default target-org config is set) or use --all

You must specify a target-org (or default target-org config is set) or use --all flag when using the --json flag.

# warning.NoAuthFoundForTargetOrg
# noAuthFoundForTargetOrg

No authenticated org found with the %s username or alias.

NOTE: Starting September 2025, this warning will be converted to an error. As a result, the exit code when you try to log out of an unauthenticated org will change from 0 to 1.
6 changes: 2 additions & 4 deletions src/commands/org/logout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,8 @@ export default class Logout extends SfCommand<AuthLogoutResults> {

if (orgAuths.length === 0) {
if (flags['target-org']) {
this.warn(messages.createWarning('warning.NoAuthFoundForTargetOrg', [flags['target-org']]));
// user specified a target org but it was not resolved, issue success message and return
this.logSuccess(messages.getMessage('logoutOrgCommandSuccess', [flags['target-org']]));
return [flags['target-org']];
// user specified a target org but it was not resolved, throw error
throw messages.createError('noAuthFoundForTargetOrg', [flags['target-org']]);
}
this.info(messages.getMessage('noOrgsFound'));
return [];
Expand Down
6 changes: 2 additions & 4 deletions test/commands/org/login/login.jwt.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ describe('org:login:jwt NUTs', () => {
await testSession?.clean();
});

afterEach(() => {
execCmd(`auth:logout -p -o ${username}`, { ensureExitCode: 0 });
});

it('should authorize an org using jwt (json)', () => {
const command = `org:login:jwt -d -o ${username} -i ${clientId} -f ${jwtKey} -r ${instanceUrl} --json`;
const json = execCmd<AuthFields>(command, { ensureExitCode: 0 }).jsonOutput?.result as AuthFields;
Expand All @@ -48,13 +44,15 @@ describe('org:login:jwt NUTs', () => {
expectUrlToExist(json, 'loginUrl');
expect(json.privateKey).to.equal(path.join(testSession.homeDir, 'jwtKey'));
expect(json.username).to.equal(username);
execCmd(`auth:logout -p -o ${username}`, { ensureExitCode: 0 });
});

it('should authorize an org using jwt (human readable)', () => {
const command = `org:login:jwt -d -o ${username} -i ${clientId} -f ${jwtKey} -r ${instanceUrl}`;
const result = execCmd(command, { ensureExitCode: 0 });
const output = getString(result, 'shellOutput.stdout');
expect(output).to.include(`Successfully authorized ${username} with org ID`);
execCmd(`auth:logout -p -o ${username}`, { ensureExitCode: 0 });
});

it('should throw correct error for JwtAuthError', () => {
Expand Down
9 changes: 7 additions & 2 deletions test/commands/org/logout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,12 @@ describe('org:logout', () => {
aliases: { TestAlias: testOrg1.username },
authInfoConfigDoesNotExist: true,
});
const response = await Logout.run(['-p', '-o', testOrg1.username, '--json']);
expect(response).to.deep.equal([testOrg1.username]);
try {
await Logout.run(['-p', '-o', testOrg1.username, '--json']);
expect.fail('Expected error to be thrown');
} catch (e) {
expect((e as Error).name).to.equal('NoAuthFoundForTargetOrgError');
expect((e as Error).message).to.include('No authenticated org found');
}
});
});
Loading