Skip to content

Commit fe1de94

Browse files
authored
fix: actually populate auth user field (#7181)
* fix: actually populate auth `user` field We were reading from the wrong property. * build: fix suppressed eslint errors * fix: revert change of empty string `NETLIFY_WEB_UI` handling * refactor: use inquirer.prompt generic
1 parent 1c27810 commit fe1de94

File tree

6 files changed

+27
-34
lines changed

6 files changed

+27
-34
lines changed

eslint_temporary_suppressions.js

-11
Original file line numberDiff line numberDiff line change
@@ -944,17 +944,6 @@ export default [
944944
'@typescript-eslint/restrict-template-expressions': 'off',
945945
},
946946
},
947-
{
948-
files: ['src/utils/gh-auth.ts'],
949-
rules: {
950-
'@typescript-eslint/no-unsafe-assignment': 'off',
951-
'@typescript-eslint/restrict-template-expressions': 'off',
952-
'@typescript-eslint/prefer-nullish-coalescing': 'off',
953-
'@typescript-eslint/no-unsafe-return': 'off',
954-
'@typescript-eslint/no-unsafe-call': 'off',
955-
'@typescript-eslint/no-unsafe-member-access': 'off',
956-
},
957-
},
958947
{
959948
files: ['src/utils/gitignore.ts'],
960949
rules: {

src/commands/init/init.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ git remote add origin https://github.com/YourUserName/RepoName.git
114114
const NEW_SITE_NO_GIT = 'Yes, create and deploy site manually'
115115
const NO_ABORT = 'No, I will connect this directory with GitHub first'
116116

117-
const { noGitRemoteChoice } = (await inquirer.prompt([
117+
const { noGitRemoteChoice } = await inquirer.prompt<{ noGitRemoteChoice: typeof NEW_SITE_NO_GIT | typeof NO_ABORT }>([
118118
{
119119
type: 'list',
120120
name: 'noGitRemoteChoice',
121121
message: 'Do you want to create a Netlify site without a git repository?',
122122
choices: [NEW_SITE_NO_GIT, NO_ABORT],
123123
},
124-
])) as { noGitRemoteChoice: typeof NEW_SITE_NO_GIT | typeof NO_ABORT }
124+
])
125125

126126
if (noGitRemoteChoice === NEW_SITE_NO_GIT) {
127127
return await createNewSiteAndExit({ state, command })
@@ -138,15 +138,15 @@ const createOrLinkSiteToRepo = async (command: BaseCommand) => {
138138

139139
const initializeOpts = [EXISTING_SITE, NEW_SITE] as const
140140

141-
const { initChoice } = (await inquirer.prompt([
141+
// TODO(serhalp): inquirer should infer the choice type here, but doesn't. Fix.
142+
const { initChoice } = await inquirer.prompt<{ initChoice: typeof initializeOpts[number] }>([
142143
{
143144
type: 'list',
144145
name: 'initChoice',
145146
message: 'What would you like to do?',
146147
choices: initializeOpts,
147148
},
148-
// TODO(serhalp): inquirer should infer the choice type here, but doesn't. Fix.
149-
])) as { initChoice: typeof initializeOpts[number] }
149+
])
150150

151151
// create site or search for one
152152
if (initChoice === NEW_SITE) {

src/utils/build-info.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import fuzzy from 'fuzzy'
44
import inquirer from 'inquirer'
55

66
import type BaseCommand from '../commands/base-command.js'
7-
import type { DefaultConfig } from '../lib/build.js'
8-
97
import { chalk, log } from './command-helpers.js'
8+
import type { DefaultConfig } from '../lib/build.js'
109

1110
/**
1211
* Filters the inquirer settings based on the input

src/utils/gh-auth.ts

+11-10
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ export interface Token {
2121
const promptForAuthMethod = async () => {
2222
const authChoiceNetlify = 'Authorize with GitHub through app.netlify.com'
2323
const authChoiceToken = 'Authorize with a GitHub personal access token'
24-
const authChoices = [authChoiceNetlify, authChoiceToken]
24+
const authChoices = [authChoiceNetlify, authChoiceToken] as const
2525

26-
const { authMethod } = await inquirer.prompt([
26+
const { authMethod } = await inquirer.prompt<{ authMethod: typeof authChoices[number] }>([
2727
{
2828
type: 'list',
2929
name: 'authMethod',
@@ -53,7 +53,7 @@ export const authWithNetlify = async (): Promise<Token> => {
5353
`${
5454
"<html><head><title>Logged in</title><script>if(history.replaceState){history.replaceState({},'','/')}</script><style>html{font-family:system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';line-height:1.5;background:rgb(18 24 31)}body{overflow:hidden;position:relative;display:flex;flex-direction:column;align-items:center;justify-content:center;height:100vh;width:100vw;}h3{margin:0}p{margin: 1rem 0 0.5rem}.card{position:relative;display:flex;flex-direction:column;width:75%;max-width:364px;padding:24px;background:white;color:rgb(18 24 31);border-radius:8px;box-shadow:rgb(6 11 16 / 20%) 0px 16px 24px, rgb(6 11 16 / 30%) 0px 6px 30px, rgb(6 11 16 / 40%) 0px 8px 10px;}</style></head>" +
5555
"<body><div class=card><h3>Logged in</h3><p>You're now logged into Netlify CLI with your "
56-
}${parameters.get('provider')} credentials. Please close this window.</p></div>`,
56+
}${parameters.get('provider') ?? ''} credentials. Please close this window.</p></div>`,
5757
)
5858
server.close()
5959
return
@@ -70,9 +70,9 @@ export const authWithNetlify = async (): Promise<Token> => {
7070
})
7171
})
7272

73-
const webUI = process.env.NETLIFY_WEB_UI || 'https://app.netlify.com'
73+
const webUI = process.env.NETLIFY_WEB_UI ?? 'https://app.netlify.com'
7474
const urlParams = new URLSearchParams({
75-
host: `http://localhost:${port}`,
75+
host: `http://localhost:${port.toString()}`,
7676
provider: 'github',
7777
})
7878
const url = `${webUI}/cli?${urlParams.toString()}`
@@ -82,13 +82,13 @@ export const authWithNetlify = async (): Promise<Token> => {
8282
return deferredPromise
8383
}
8484

85-
const getPersonalAccessToken = async () => {
86-
const { token } = await inquirer.prompt([
85+
const getPersonalAccessToken = async (): Promise<{ token: string }> => {
86+
const { token } = await inquirer.prompt<{ token: string }>([
8787
{
8888
type: 'password',
8989
name: 'token',
9090
message: 'Your GitHub personal access token:',
91-
filter: (input) => input.trim(),
91+
filter: (input: string) => input.trim(),
9292
},
9393
])
9494

@@ -105,8 +105,9 @@ const authWithToken = async (): Promise<Token> => {
105105
}
106106

107107
const octokit = new Octokit({ auth: `token ${token}` })
108-
// @ts-expect-error -- XXX(serhalp): actual bug - fixed in stacked PR
109-
const { login: user } = await octokit.users.getAuthenticated()
108+
const {
109+
data: { login: user },
110+
} = await octokit.users.getAuthenticated()
110111

111112
return { token, user, provider: 'github' }
112113
}

src/utils/init/config-manual.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ const addDeployKey = async (deployKey: DeployKey) => {
3030
}
3131

3232
const getRepoPath = async ({ repoData }: { repoData: RepoData }): Promise<string> => {
33-
const { repoPath } = (await inquirer.prompt([
33+
const { repoPath } = await inquirer.prompt<{ repoPath: string }>([
3434
{
3535
type: 'input',
3636
name: 'repoPath',
3737
message: 'The SSH URL of the remote git repo:',
3838
default: repoData.url,
3939
validate: (url: string) => (SSH_URL_REGEXP.test(url) ? true : 'The URL provided does not use the SSH protocol'),
4040
},
41-
])) as { repoPath: string }
41+
])
4242

4343
return repoPath
4444
}
@@ -48,14 +48,14 @@ const addDeployHook = async (deployHook: string | undefined): Promise<boolean> =
4848
// FIXME(serhalp): Handle nullish `deployHook` by throwing user-facing error or fixing upstream type.
4949
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
5050
log(`\n${deployHook}\n\n`)
51-
const { deployHookAdded } = (await inquirer.prompt([
51+
const { deployHookAdded } = await inquirer.prompt<{ deployHookAdded: boolean }>([
5252
{
5353
type: 'confirm',
5454
name: 'deployHookAdded',
5555
message: 'Continue?',
5656
default: true,
5757
},
58-
])) as { deployHookAdded: boolean }
58+
])
5959

6060
return deployHookAdded
6161
}

src/utils/init/utils.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,17 @@ export const getBuildSettings = async ({
105105
log()
106106
}
107107

108-
const { baseDir, buildCmd, buildDir } = (await inquirer.prompt(
108+
const { baseDir, buildCmd, buildDir } = await inquirer.prompt<{
109+
baseDir?: string | undefined
110+
buildCmd: string
111+
buildDir: string
112+
}>(
109113
getPromptInputs({
110114
defaultBaseDir,
111115
defaultBuildCmd,
112116
defaultBuildDir,
113117
}),
114-
)) as { baseDir?: string | undefined; buildCmd: string; buildDir: string }
118+
)
115119

116120
const pluginsToInstall = recommendedPlugins.map((plugin) => ({ package: plugin }))
117121
const normalizedBaseDir = baseDir ? normalizeBackslash(baseDir) : undefined

0 commit comments

Comments
 (0)