Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// get issue according to title first
_a.issue = _c.sent();
if (!!this.issue) return [3 /*break*/, 3];
// require login to create the issue
if (!this.authStatus.isLogined) {
this.$emit('login');
}
// if current user is not admin, cannot create issue
if (!this.authStatus.isAdmin) {
throw Error('Failed to get comments');
}
// create the corresponding issue
_b = this;
return [4 /*yield*/, this.API.postIssue({
title: issueTitle,
content: getCleanURL(window.location.href),
accessToken: this.accessToken
})];
case 2:
// create the corresponding issue
_b.issue = _c.sent();
_c.label = 3;
case 3:
// try to load comments
return [4 /*yield*/, this.getComments()];
case 4:
// try to load comments
_c.sent();
return [2 /*return*/];
}
});
});
if (!this.API || !this.options || this.issue || this.issueId)
return;
// login to create issue
if (!this.isLogined) {
this.login();
}
// only owner/admins can create issue
if (!this.isAdmin)
return;
try {
this.isCreatingIssue = true;
const issue = await this.API.postIssue({
title: this.issueTitle,
content: await this.options.issueContent({
options: this.options,
url: getCleanURL(window.location.href),
}),
accessToken: this.accessToken,
});
this.issue = issue;
this.isIssueNotCreated = false;
await this.getComments();
}
catch (e) {
this.isFailed = true;
}
finally {
this.isCreatingIssue = false;
}
}
/**
async handleAuth (): Promise {
const query = parseQuery(window.location.search)
if (query.code) {
if (query.state !== this.state) {
return null
}
const code = query.code
delete query.code
delete query.state
const replaceURL = buildURL(getCleanURL(window.location.href), query) + window.location.hash
window.history.replaceState(null, '', replaceURL)
const accessToken = await this.getAccessToken({ code })
return accessToken
}
return null
}
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
query = parseQuery(window.location.search);
if (!query.code) return [3 /*break*/, 2];
code = query.code;
delete query.code;
replaceURL = buildURL(getCleanURL(window.location.href), query) + window.location.hash;
window.history.replaceState(null, '', replaceURL);
return [4 /*yield*/, this.getAccessToken({ code: code })];
case 1:
accessToken = _a.sent();
return [2 /*return*/, accessToken];
case 2: return [2 /*return*/, null];
}
});
});
async handleAuth (): Promise {
const query = parseQuery(window.location.search)
if (query.code) {
if (query.state !== this.state) {
return null
}
const code = query.code
delete query.code
delete query.state
const replaceURL = buildURL(getCleanURL(window.location.href), query) + window.location.hash
window.history.replaceState(null, '', replaceURL)
const accessToken = await this.getAccessToken({ code })
return accessToken
}
return null
}
async handleAuth (): Promise {
const query = parseQuery(window.location.search)
if (query.code) {
const code = query.code
delete query.code
const replaceURL = buildURL(getCleanURL(window.location.href), query) + window.location.hash
window.history.replaceState(null, '', replaceURL)
const accessToken = await this.getAccessToken({ code })
return accessToken
}
return null
}
async handleAuth (): Promise {
const hash = parseQuery(window.location.hash.slice(1))
if (!hash.access_token || hash.state !== this.state) {
return null
}
const accessToken = hash.access_token
delete hash.access_token
delete hash.token_type
delete hash.expires_in
delete hash.state
const hashString = buildQuery(hash)
const newHash = hashString ? `#${hashString}` : ''
const replaceURL = `${getCleanURL(window.location.href)}${window.location.search}${newHash}`
window.history.replaceState(null, '', replaceURL)
return accessToken
}
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
query = parseQuery(window.location.search);
if (!query.code) return [3 /*break*/, 2];
if (query.state !== this.state) {
return [2 /*return*/, null];
}
code = query.code;
delete query.code;
delete query.state;
replaceURL = buildURL(getCleanURL(window.location.href), query) + window.location.hash;
window.history.replaceState(null, '', replaceURL);
return [4 /*yield*/, this.getAccessToken({ code: code })];
case 1:
accessToken = _a.sent();
return [2 /*return*/, accessToken];
case 2: return [2 /*return*/, null];
}
});
});
get: function () {
return utils.getCleanURL(window.location.href);
},
enumerable: true,
async handleAuth (): Promise {
const query = parseQuery(window.location.search)
if (query.code) {
if (query.state !== this.state) {
return null
}
const code = query.code
delete query.code
delete query.state
const replaceURL = buildURL(getCleanURL(window.location.href), query) + window.location.hash
window.history.replaceState(null, '', replaceURL)
const accessToken = await this.getAccessToken({ code })
return accessToken
}
return null
}