Skip to content

Commit 21a55b9

Browse files
authored
fix(gh-auth): minor refactoring (#3965)
1 parent cd8670b commit 21a55b9

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/utils/gh-auth.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,14 @@ const getPersonalAccessToken = async () => {
102102
*/
103103
const authWithToken = async () => {
104104
const { token } = await getPersonalAccessToken()
105-
if (token) {
106-
const octokit = new Octokit({
107-
auth: `token ${token}`,
108-
})
109-
const { login: user } = await octokit.users.getAuthenticated()
110-
return { token, user, provider: 'github' }
105+
if (!token) {
106+
throw new Error('GitHub authentication failed')
111107
}
112-
const error = new Error('GitHub authentication failed')
113-
throw error
108+
109+
const octokit = new Octokit({ auth: `token ${token}` })
110+
const { login: user } = await octokit.users.getAuthenticated()
111+
112+
return { token, user, provider: 'github' }
114113
}
115114

116115
/**
@@ -121,11 +120,8 @@ const getGitHubToken = async () => {
121120
log('')
122121

123122
const withNetlify = await promptForAuthMethod()
124-
if (withNetlify) {
125-
return await authWithNetlify()
126-
}
127123

128-
return await authWithToken()
124+
return withNetlify ? await authWithNetlify() : await authWithToken()
129125
}
130126

131127
module.exports = { getGitHubToken, authWithNetlify }

0 commit comments

Comments
 (0)