Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
v1.0.0-alpha.4
Browse files Browse the repository at this point in the history
  • Loading branch information
walaszczykm committed Jul 31, 2022
1 parent 10cd114 commit caa0dd6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 35 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@livechat/dev-cli",
"version": "1.0.0-alpha.3",
"version": "1.0.0-alpha.4",
"description": "This project exposes LiveChat Developer Console capabilities in form of easy to use CLI application.",
"publishConfig": {
"access": "public"
Expand All @@ -16,7 +16,7 @@
"boxen": "^6.2.1",
"configstore": "^6.0.0",
"gradient-string": "^2.0.0",
"micro": "9.4.0",
"micro": "9.4.1",
"node-fetch": "^3.2.3",
"open": "^8.4.0",
"ora": "^6.1.0",
Expand Down
49 changes: 23 additions & 26 deletions src/lib/obtain-auth-data.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
import open from 'open'
import http from 'http'
import micro, { send } from 'micro'
import { config } from './config'
import { AccountsService } from '../services/accounts'

export async function obtainAuthData() {
return new Promise((resolve, reject) => {
const server = http.Server(
micro(async (req, res) => {
const { searchParams } = new URL(`${config.webServerUrl}${req.url}`)
if (searchParams.has('code')) {
try {
const data = await AccountsService.codeGrant({ code: searchParams.get('code').replace('%3A', ':') })
server.close((error) => {
if (error) {
reject(error)
} else {
resolve(data)
}
})
} catch (error) {
server.close(() => {
const server = micro(async (req, res) => {
const { searchParams } = new URL(`${config.webServerUrl}${req.url}`)
if (searchParams.has('code')) {
try {
const data = await AccountsService.codeGrant({ code: searchParams.get('code').replace('%3A', ':') })
server.close((error) => {
if (error) {
reject(error)
})
return
}
} else {
resolve(data)
}
})
} catch (error) {
server.close(() => {
reject(error)
})
return
}
}

send(
res,
200,
`
send(
res,
200,
`
<html>
<style>
.center {
Expand Down Expand Up @@ -58,9 +56,8 @@ export async function obtainAuthData() {
</body>
</html>
`,
)
}),
)
)
})

const url = new URL(config.accountsUrl)
url.searchParams.set('response_type', 'code')
Expand Down

0 comments on commit caa0dd6

Please sign in to comment.