mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-05-23 09:39:48 +02:00
fix: fix getToken function
This commit is contained in:
+13
-15
@@ -51,26 +51,24 @@ export default abstract class GitHubBase {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getToken(owner?: string) {
|
async getToken() {
|
||||||
if (owner) {
|
const user = await UserModel.findOne({ id: this.repository.owner.id });
|
||||||
const user = await UserModel.findOne({ username: owner });
|
if (user && user.accessTokens.github) {
|
||||||
if (user && user.accessTokens.github) {
|
return user.accessTokens.github as string;
|
||||||
return user.accessTokens.github as string;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (this.accessToken) {
|
if (this.accessToken) {
|
||||||
try {
|
try {
|
||||||
const app = new OAuthApp({
|
// const app = new OAuthApp({
|
||||||
clientType: "github-app",
|
// clientType: "github-app",
|
||||||
clientId: config.CLIENT_ID,
|
// clientId: config.CLIENT_ID,
|
||||||
clientSecret: config.CLIENT_SECRET,
|
// clientSecret: config.CLIENT_SECRET,
|
||||||
});
|
// });
|
||||||
await app.checkToken({
|
// await app.checkToken({
|
||||||
token: this.accessToken,
|
// token: this.accessToken,
|
||||||
});
|
// });
|
||||||
return this.accessToken;
|
return this.accessToken;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// console.debug("Token is invalid.", error);
|
console.debug("[ERROR] Token is invalid", this.repository.repoId);
|
||||||
this.accessToken = config.GITHUB_TOKEN;
|
this.accessToken = config.GITHUB_TOKEN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user