Skip to content

Commit

Permalink
fix(gh-auth): minor refactoring (#3965)
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Jan 6, 2022
1 parent cd8670b commit 21a55b9
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/utils/gh-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,14 @@ const getPersonalAccessToken = async () => {
*/
const authWithToken = async () => {
const { token } = await getPersonalAccessToken()
if (token) {
const octokit = new Octokit({
auth: `token ${token}`,
})
const { login: user } = await octokit.users.getAuthenticated()
return { token, user, provider: 'github' }
if (!token) {
throw new Error('GitHub authentication failed')
}
const error = new Error('GitHub authentication failed')
throw error

const octokit = new Octokit({ auth: `token ${token}` })
const { login: user } = await octokit.users.getAuthenticated()

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

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

const withNetlify = await promptForAuthMethod()
if (withNetlify) {
return await authWithNetlify()
}

return await authWithToken()
return withNetlify ? await authWithNetlify() : await authWithToken()
}

module.exports = { getGitHubToken, authWithNetlify }

1 comment on commit 21a55b9

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

Package size: 359 MB

Please sign in to comment.