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
5 changes: 4 additions & 1 deletion src/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ export async function login(
interval: number;
};

const verificationUri = `${new URL(base).origin}/activate`;
// Points at the API, which redirects to the dashboard SPA — the CLI only
// knows the API origin, and the approval page lives on the app. The code
// travels in the link so following it is a single confirmation.
const verificationUri = `${base}/device?code=${encodeURIComponent(userCode)}`;
onPrompt(userCode, verificationUri);

const deadline = now() + expiresIn * 1000;
Expand Down
7 changes: 6 additions & 1 deletion tests/login.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ describe('login', () => {
const result = await login(config(), onPrompt, { fetchImpl: fetchImpl as never, ...noSleep });

expect(result.status).toBe('approved');
expect(onPrompt).toHaveBeenCalledWith('WDJB-MJHT', 'https://api.patchstack.com/activate');
// The API redirects this to the dashboard SPA; the code rides along so
// following the link is one confirmation rather than a retype.
expect(onPrompt).toHaveBeenCalledWith(
'WDJB-MJHT',
'https://api.patchstack.com/monitor/pulse/device?code=WDJB-MJHT',
);

// Both fields: approving rotates the one secret block-logs use too, so
// leaving apiKey behind would break block-log reporting.
Expand Down
Loading