@faable/faable 1.5.33 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/api/auth.js CHANGED
@@ -1,11 +1,24 @@
1
1
  import axios from 'axios';
2
+ import os from 'os';
2
3
 
3
4
  const api = axios.create({ baseURL: "https://faable.auth.faable.link" });
4
5
  const CLIENT_ID = "c879023b-e34f-4b0c-a262-210e556bc2e4";
6
+ const PLATFORM_LABELS = {
7
+ darwin: "macOS",
8
+ win32: "Windows",
9
+ linux: "Linux",
10
+ };
11
+ // Human-friendly device name shown on the auth confirm page so the user can
12
+ // recognise which device they are authorising, e.g. "marcs-mbp (macOS)".
13
+ function deviceName() {
14
+ const platform = PLATFORM_LABELS[os.platform()] || os.platform();
15
+ return `${os.hostname()} (${platform})`;
16
+ }
5
17
  async function getDeviceCode() {
6
18
  const res = await api.post(`/oauth/device/code`, {
7
19
  client_id: CLIENT_ID,
8
20
  scope: "openid email profile offline_access",
21
+ device_name: deviceName(),
9
22
  });
10
23
  return res.data;
11
24
  }
@@ -3,6 +3,7 @@ import { getDeviceCode, getDeviceToken, getMe } from '../../api/auth.js';
3
3
  import { CredentialsStore } from '../../lib/CredentialsStore.js';
4
4
  import open from 'open';
5
5
  import ora from 'ora';
6
+ import prompts from 'prompts';
6
7
  import { log } from '../../log.js';
7
8
 
8
9
  const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
@@ -41,6 +42,26 @@ const login = {
41
42
  handler: async (args) => {
42
43
  const { apikey, token } = args;
43
44
  const store = new CredentialsStore();
45
+ // Interactive flow only: if there's already a session, confirm before
46
+ // re-authenticating. Flag-based logins (--apikey/--token) are an explicit
47
+ // re-auth (and often scripted), so they skip the prompt and overwrite.
48
+ if (!apikey && !token) {
49
+ const existing = await store.loadCredentials();
50
+ if (existing && (existing.token || existing.apikey)) {
51
+ const who = existing.email ? ` as ${existing.email}` : "";
52
+ const { proceed } = await prompts({
53
+ type: "confirm",
54
+ name: "proceed",
55
+ message: `You are already logged in${who}. Log out and log in again?`,
56
+ initial: false,
57
+ });
58
+ if (!proceed) {
59
+ log.info("Keeping current session. Run `faable logout` to log out.");
60
+ return;
61
+ }
62
+ await store.deleteCredentials();
63
+ }
64
+ }
44
65
  if (apikey) {
45
66
  log.info("Logging in with API Key...");
46
67
  const tempApi = FaableApi.create({ auth: { apikey }, authStrategy: (await import('../../api/strategies/apikey.strategy.js')).apikey_strategy });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faable/faable",
3
- "version": "1.5.33",
3
+ "version": "1.6.0",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "author": "Marc Pomar <marc@faable.com>",