Merge pull request #543 from netlify/isCollaborator-fix
Fix denied login for users with many repos.
This commit is contained in:
commit
06e5c9d7a2
@ -19,17 +19,13 @@ export default class API {
|
|||||||
return this.request("/user");
|
return this.request("/user");
|
||||||
}
|
}
|
||||||
|
|
||||||
isCollaborator(user) {
|
hasWriteAccess() {
|
||||||
return this.request('/user/repos').then((repos) => {
|
return this.request(this.repoURL)
|
||||||
let contributor = false
|
.then(repo => repo.permissions.push)
|
||||||
for (const repo of repos) {
|
.catch(error => {
|
||||||
if (repo.full_name.toLowerCase() === this.repo.toLowerCase() && repo.permissions.push) contributor = true;
|
console.error("Problem fetching repo data from GitHub");
|
||||||
}
|
throw error;
|
||||||
return contributor;
|
});
|
||||||
}).catch((error) => {
|
|
||||||
console.error("Problem with response of /user/repos from GitHub");
|
|
||||||
throw error;
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
requestHeaders(headers = {}) {
|
requestHeaders(headers = {}) {
|
||||||
|
@ -32,7 +32,7 @@ export default class GitHub {
|
|||||||
this.token = state.token;
|
this.token = state.token;
|
||||||
this.api = new API({ token: this.token, branch: this.branch, repo: this.repo, api_root: this.api_root });
|
this.api = new API({ token: this.token, branch: this.branch, repo: this.repo, api_root: this.api_root });
|
||||||
return this.api.user().then(user =>
|
return this.api.user().then(user =>
|
||||||
this.api.isCollaborator(user.login).then((isCollab) => {
|
this.api.hasWriteAccess().then((isCollab) => {
|
||||||
// Unauthorized user
|
// Unauthorized user
|
||||||
if (!isCollab) throw new Error("Your GitHub user account does not have access to this repo.");
|
if (!isCollab) throw new Error("Your GitHub user account does not have access to this repo.");
|
||||||
// Authorized user
|
// Authorized user
|
||||||
|
Loading…
x
Reference in New Issue
Block a user