@glash/cli 0.2.38 → 0.2.39

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.
Files changed (2) hide show
  1. package/commands/login.mjs +16 -5
  2. package/package.json +1 -1
@@ -7,6 +7,17 @@ import { prompt, ok, fail, info, warn, color } from '../lib/ui.mjs';
7
7
 
8
8
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
9
9
 
10
+ async function identityPost(path, body, opts) {
11
+ try {
12
+ return await apiPost(`/identity${path}`, body, opts);
13
+ } catch (e) {
14
+ if (e?.status === 404) {
15
+ return apiPost(`/auth${path}`, body, opts);
16
+ }
17
+ throw e;
18
+ }
19
+ }
20
+
10
21
  function openBrowser(url) {
11
22
  try {
12
23
  const opener = platform === 'darwin' ? 'open' : platform === 'win32' ? 'cmd' : 'xdg-open';
@@ -29,7 +40,7 @@ export async function login({ flags }) {
29
40
  async function browserLogin(flags) {
30
41
  let start;
31
42
  try {
32
- start = await apiPost('/auth/cli/device/start', { deviceName: hostname() });
43
+ start = await identityPost('/cli/device/start', { deviceName: hostname() });
33
44
  } catch (e) {
34
45
  // Older backend without device auth — fall back to password login.
35
46
  warn('Browser login is unavailable; falling back to email/password.');
@@ -60,7 +71,7 @@ async function browserLogin(flags) {
60
71
  await sleep(delay);
61
72
  let r;
62
73
  try {
63
- r = await apiPost('/auth/cli/device/poll', { deviceCode });
74
+ r = await identityPost('/cli/device/poll', { deviceCode });
64
75
  } catch (e) {
65
76
  return fail(e.message);
66
77
  }
@@ -84,16 +95,16 @@ async function passwordLogin(flags) {
84
95
  if (!email || !password) return fail('email and password required');
85
96
 
86
97
  try {
87
- let r = await apiPost('/auth/login', { email, password });
98
+ let r = await identityPost('/login', { email, password });
88
99
 
89
100
  // Second factor is always required. Complete the email-OTP challenge.
90
101
  if (!r?.accessToken && r?.secondFactorRequired && !r?.challengeId) {
91
- r = await apiPost('/auth/login', { email, password, secondFactorMethod: 'email_otp' });
102
+ r = await identityPost('/login', { email, password, secondFactorMethod: 'email_otp' });
92
103
  }
93
104
  if (!r?.accessToken && (r?.otpRequired || r?.challengeId)) {
94
105
  const code = flags.otp || (await prompt('Enter the 6-digit code sent to your email: '));
95
106
  if (!code) throw new Error('A verification code is required to sign in.');
96
- r = await apiPost('/auth/login', {
107
+ r = await identityPost('/login', {
97
108
  email,
98
109
  password,
99
110
  emailOtpCode: String(code).trim(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glash/cli",
3
- "version": "0.2.38",
3
+ "version": "0.2.39",
4
4
  "description": "glashDB command-line interface — deploy projects, pull source + env, manage env vars.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://glashdb.com",