Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/commands/base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
USER_AGENT,
chalk,
logAndThrowError,
logJson,
exit,
getToken,
log,
Expand Down Expand Up @@ -516,7 +517,26 @@ export default class BaseCommand extends Command {
const authLink = `${webUI}/authorize?response_type=ticket&ticket=${ticket.id}`

log(`Opening ${authLink}`)
await openBrowser({ url: authLink })
const browserOpened = await openBrowser({ url: authLink })

if (!browserOpened && !isInteractive() && ticket.id) {
const ticketId = ticket.id
logJson({
ticket_id: ticketId,
url: authLink,
check_command: `netlify login --check ${ticketId}`,
agent_next_steps:
'Give the URL to the user so they can authorize. Then poll the check_command for up to ten minutes to see if the user has logged in, or wait for them to tell you and then use check_command after.',
})
log(`Ticket ID: ${ticketId}`)
log(`Authorize URL: ${authLink}`)
log()
log(`After authorizing, run: netlify login --check ${ticketId}`)
log()
log('After user opens the authorization URL and approves, the login will be complete.')
return exit()
}

log()
log(`To request authorization from a human, run: ${chalk.cyanBright('netlify login --request "<msg>"')}`)
log()
Expand Down
7 changes: 0 additions & 7 deletions src/commands/login/login.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { OptionValues } from 'commander'

import { chalk, exit, getToken, log, logAndThrowError } from '../../utils/command-helpers.js'
import { isInteractive } from '../../utils/scripted-commands.js'
import { TokenLocation } from '../../utils/types.js'
import BaseCommand from '../base-command.js'

Expand Down Expand Up @@ -51,11 +50,5 @@ export const login = async (options: OptionValues, command: BaseCommand) => {
return exit()
}

if (!isInteractive()) {
const { loginRequest } = await import('./login-request.js')
await loginRequest('CLI session', command.netlify.apiOpts)
return
}

await command.expensivelyAuthenticate()
}
8 changes: 5 additions & 3 deletions src/utils/open-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,26 @@ type OpenBrowsrProps = {
url: string
}

const openBrowser = async function ({ silentBrowserNoneError, url }: OpenBrowsrProps) {
const openBrowser = async function ({ silentBrowserNoneError, url }: OpenBrowsrProps): Promise<boolean> {
if (isDockerContainer()) {
unableToOpenBrowserMessage({ url, message: 'Running inside a docker container' })
return
return false
}
if (process.env.BROWSER === 'none') {
if (!silentBrowserNoneError) {
unableToOpenBrowserMessage({ url, message: "BROWSER environment variable is set to 'none'" })
}
return
return false
}

try {
await open(url)
return true
} catch (error) {
if (error instanceof Error) {
unableToOpenBrowserMessage({ url, message: error.message })
}
return false
}
}

Expand Down
Loading