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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- **`coursecode login` after Deny:** The browser sign-in fallback (used when Cloud has no device-code login) now stops as soon as you click Deny and says so, instead of waiting until the login times out.

## [0.4.5] - 2026-11-06

### Added
Expand Down
9 changes: 9 additions & 0 deletions lib/cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,15 @@ async function runLegacyLoginFlow() {
process.exit(1);
}

// 400 is final: the user clicked Deny (or the session is invalid).
if (pollRes.status === 400) {
let body = {};
try { body = JSON.parse(await pollRes.text()); } catch { /* ignore */ }
const reason = body.error === 'Denied' ? 'was denied in the browser' : `failed: ${body.error || 'HTTP 400'}`;
console.error(`\n❌ Login ${reason}. Run \`coursecode login\` to try again.\n`);
process.exit(1);
}

if (!pollRes.ok) continue;

const data = JSON.parse(await pollRes.text());
Expand Down
30 changes: 30 additions & 0 deletions tests/lib/cloud-auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,36 @@ describe('cloud auth and binding regression guards', () => {
expect(stdoutSpy).toHaveBeenCalled();
});

it('legacy login stops polling as soon as the user clicks Deny', async () => {
vi.resetModules();
mockOsHome(tempHome);
vi.doMock('child_process', async () => {
const actual = await vi.importActual('child_process');
const execFile = vi.fn(() => ({ on: vi.fn() }));
return { ...actual, default: { ...actual.default, execFile }, execFile };
});

const fetchMock = mockCloudFetchSequence([
// No device-code endpoint → legacy nonce flow
{ ok: false, status: 404, body: { error: 'Not found' } },
{ ok: true, status: 200, body: { ok: true } },
{ ok: false, status: 400, body: { error: 'Denied' } },
]);

vi.spyOn(console, 'log').mockImplementation(() => {});
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
vi.spyOn(process, 'exit').mockImplementation((code) => {
throw new Error(`process.exit(${code})`);
});

const cloud = await import('../../lib/cloud.js');
await expect(cloud.login()).rejects.toThrow('process.exit(1)');

expect(fetchMock).toHaveBeenCalledTimes(3);
expect(errorSpy.mock.calls.flat().join(' ')).toContain('denied in the browser');
expect(fs.existsSync(path.join(tempHome, '.coursecode', 'credentials.json'))).toBe(false);
}, 10_000);

it('status resolves slug from local project config and keeps org query behavior', async () => {
fs.mkdirSync(path.join(tempProject, '.coursecode'), { recursive: true });
fs.writeFileSync(
Expand Down
Loading