Skip to content

Commit e3a3d63

Browse files
committed
unify the re-auth paths
1 parent 1d1e1fa commit e3a3d63

File tree

1 file changed

+4
-23
lines changed

1 file changed

+4
-23
lines changed

src/init.ts

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ import { exec } from 'child_process'
33
import { promisify } from 'util'
44
import {
55
AccountInfo,
6+
ensureWranglerAuthentication,
67
fetchInternal,
78
FetchResult,
8-
getAuthTokens,
9-
isAccessTokenExpired,
109
isDirectory,
11-
refreshToken,
1210
} from './utils/wrangler'
1311
import chalk from 'chalk'
1412
import os from 'node:os'
@@ -37,29 +35,12 @@ export async function init(accountTag: string | undefined) {
3735
startSection(`Checking for existing Wrangler auth info`, `Step 1 of 3`)
3836
updateStatus(chalk.gray(`If anything goes wrong, try running 'npx wrangler@latest login' manually and retrying.`))
3937

40-
try {
41-
getAuthTokens()
42-
} catch (e: any) {
43-
updateStatus(`${chalk.underline.red('Warning:')} ${chalk.gray(e.message)}`, false)
44-
updateStatus(`Running '${chalk.yellow('npx wrangler login')}' and retrying...`, false)
45-
46-
const { stderr, stdout } = await execAsync('npx wrangler@latest login')
47-
if (stderr) updateStatus(chalk.gray(stderr))
48-
49-
getAuthTokens()
38+
const authenticated = await ensureWranglerAuthentication()
39+
if (!authenticated) {
40+
throw new Error('Failed to authenticate with Wrangler. Please try running npx wrangler@latest login manually and then retry.')
5041
}
5142

5243
updateStatus(`Wrangler auth info loaded!`)
53-
54-
if (isAccessTokenExpired()) {
55-
updateStatus(`Access token expired, refreshing...`, false)
56-
if (await refreshToken()) {
57-
updateStatus('Successfully refreshed access token')
58-
} else {
59-
throw new Error('Failed to refresh access token')
60-
}
61-
}
62-
6344
endSection('Done')
6445
startSection(`Fetching account info`, `Step 2 of 3`)
6546

0 commit comments

Comments
 (0)