Skip to content

fix github token api call #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 4 additions & 5 deletions src/components/OutputPan.vue
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,9 @@ export default {
activePan: this.activePan
}
)
const params = {}
const headers = {}
if (token) {
// eslint-disable-next-line camelcase
params.access_token = token
headers['Authorization'] = 'token ' + token
}
const shouldUpdateGist = this.canUpdateGist && !saveNew
const url = `https://api.github.com/gists${
Expand All @@ -274,7 +273,7 @@ export default {
}`
const method = shouldUpdateGist ? 'PATCH' : 'POST'
const { data } = await axios(url, {
params,
headers,
method,
data: {
public: false,
Expand All @@ -290,7 +289,7 @@ export default {
// Update gist id in the description of newly created gist
axios(`https://api.github.com/gists/${data.id}`, {
method: 'PATCH',
params,
headers,
data: {
description: `Try it online! https://codepan.net/gist/${
data.id
Expand Down
10 changes: 4 additions & 6 deletions src/utils/github-api.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import axios from 'axios'
import notie from 'notie'

export default async function (endpoint, token, errCb = () => {}) {
const params = {
// eslint-disable-next-line camelcase
access_token: token
}
export default async function (endpoint, token, errCb = () => { }) {

const headers = { 'Authorization': 'token ' + token };

try {
const data = await axios.get(`https://api.github.com/${endpoint}`, {
params
headers
}).then(res => res.data)

return data
Expand Down