Skip to content

Commit 5a1b628

Browse files
committed
fix: login command
1 parent 19e13d4 commit 5a1b628

3 files changed

Lines changed: 27 additions & 7 deletions

File tree

.mcp.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"mcpServers": {
3+
"playwright": {
4+
"type": "stdio",
5+
"command": "npx",
6+
"args": [
7+
"-y",
8+
"@playwright/mcp@latest"
9+
],
10+
"env": {}
11+
}
12+
}
13+
}

src/api/auth.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,13 @@ export async function getDeviceToken(device_code: string) {
2828
}>(`/oauth/token`, { device_code, client_id:CLIENT_ID, grant_type:"urn:ietf:params:oauth:grant-type:device_code" });
2929
return res.data;
3030
}
31+
32+
// Validate a device-flow access token against the Faable Auth server. The token
33+
// is issued by the auth server, so it must be introspected there — NOT against
34+
// the deploy API (api.faable.com), which has no /me route and would 404.
35+
export async function getMe(access_token: string) {
36+
const res = await api.get<{ email: string; id: string }>(`/me`, {
37+
headers: { Authorization: `Bearer ${access_token}` },
38+
});
39+
return res.data;
40+
}

src/commands/login/index.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { CommandModule } from "yargs";
22
import { FaableApi } from "../../api/FaableApi";
3-
import { getDeviceCode, getDeviceToken } from "../../api/auth";
3+
import { getDeviceCode, getDeviceToken, getMe } from "../../api/auth";
44
import { CredentialsStore } from "../../lib/CredentialsStore";
5-
import { bearer_strategy } from "../../api/strategies/bearer.strategy";
65
import open from "open";
76
import ora from "ora";
87
import { log } from "../../log";
@@ -139,11 +138,9 @@ export const login: CommandModule = {
139138
const { access_token } = await getDeviceToken(device_code);
140139
if (access_token) {
141140
spinner.stop();
142-
const tempApi = FaableApi.create({
143-
auth: { token: access_token },
144-
authStrategy: bearer_strategy,
145-
});
146-
const me = await tempApi.getMe();
141+
// Validate the freshly issued token against the Auth server (it
142+
// issued the token). The deploy API has no /me route.
143+
const me = await getMe(access_token);
147144
await store.saveCredentials({ token: access_token, email: me.email });
148145
log.info(`✅ Successfully logged in as ${me.email}`);
149146
return;

0 commit comments

Comments
 (0)