ship2-cli 0.2.0 → 0.2.1

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/deploy.js +44 -1
  2. package/package.json +1 -1
@@ -72,7 +72,14 @@ async function checkSubdomain(subdomain, token, apiBase) {
72
72
  'Authorization': `Bearer ${token}`
73
73
  }
74
74
  })
75
- return await response.json()
75
+ const data = await response.json()
76
+
77
+ // Handle unauthorized - token expired
78
+ if (response.status === 401 || data.error === 'unauthorized') {
79
+ return { error: 'unauthorized', authError: true }
80
+ }
81
+
82
+ return data
76
83
  } catch (err) {
77
84
  return { error: err.message }
78
85
  }
@@ -85,6 +92,13 @@ async function selectSubdomain(suggestedName, token, apiBase, isJson) {
85
92
  // First check if suggested name is available
86
93
  const check = await checkSubdomain(suggestedName, token, apiBase)
87
94
 
95
+ // Handle auth error
96
+ if (check.authError) {
97
+ console.log(chalk.red('\n Session expired. Please login again.'))
98
+ console.log(chalk.dim(' Run: ship2 login\n'))
99
+ process.exit(1)
100
+ }
101
+
88
102
  if (check.available) {
89
103
  if (check.owned) {
90
104
  // User owns this subdomain, will update
@@ -129,6 +143,13 @@ async function selectSubdomain(suggestedName, token, apiBase, isJson) {
129
143
  const checkResult = await checkSubdomain(sanitized, token, apiBase)
130
144
  spinner.stop()
131
145
 
146
+ // Handle auth error
147
+ if (checkResult.authError) {
148
+ console.log(chalk.red('\n Session expired. Please login again.'))
149
+ console.log(chalk.dim(' Run: ship2 login\n'))
150
+ process.exit(1)
151
+ }
152
+
132
153
  if (checkResult.error) {
133
154
  console.log(chalk.red(` Error: ${checkResult.error}`))
134
155
  continue
@@ -227,6 +248,17 @@ export default async function deploy(inputPath, options) {
227
248
 
228
249
  // Check if available
229
250
  const check = await checkSubdomain(sanitized, token, apiBase)
251
+
252
+ // Handle auth error first
253
+ if (check.authError) {
254
+ output.deployError({
255
+ code: 'UNAUTHORIZED',
256
+ message: 'Session expired. Please login again.',
257
+ suggestion: 'Run: ship2 login'
258
+ }, isJson)
259
+ process.exit(1)
260
+ }
261
+
230
262
  if (!check.available && !check.owned) {
231
263
  output.deployError({
232
264
  code: 'NAME_TAKEN',
@@ -260,6 +292,17 @@ export default async function deploy(inputPath, options) {
260
292
  } else {
261
293
  // JSON mode without --name: use suggested name, check availability
262
294
  const check = await checkSubdomain(suggestedName, token, apiBase)
295
+
296
+ // Handle auth error first
297
+ if (check.authError) {
298
+ output.deployError({
299
+ code: 'UNAUTHORIZED',
300
+ message: 'Session expired. Please login again.',
301
+ suggestion: 'Run: ship2 login'
302
+ }, isJson)
303
+ process.exit(1)
304
+ }
305
+
263
306
  if (!check.available && !check.owned) {
264
307
  output.deployError({
265
308
  code: 'NAME_TAKEN',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ship2-cli",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Deploy static sites and Next.js apps to ship2.app in seconds",
5
5
  "main": "lib/index.js",
6
6
  "bin": {