Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
🐛 Throw correct OAuth error
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Oct 6, 2019
1 parent 132cfb3 commit a21a3c6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@staart/manager",
"version": "1.1.48",
"version": "1.1.49",
"main": "index.js",
"repository": "[email protected]:AnandChowdhary/staart.git",
"author": "Anand Chowdhary <[email protected]>",
Expand Down Expand Up @@ -149,5 +149,5 @@
"setup"
],
"snyk": true,
"staart-version": "1.1.48"
"staart-version": "1.1.49"
}
19 changes: 10 additions & 9 deletions src/crud/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,26 +614,27 @@ export const createIdentityConnect = async (
code: string
) => {
if (service === "github") {
let data: any;
try {
const token = (await github.code.getToken(
`${FRONTEND_URL}/auth/connect-identity/github?code=${code}`
)).accessToken;
const data = (await Axios.get("https://api.github.com/user", {
data = (await Axios.get("https://api.github.com/user", {
headers: {
Authorization: `token ${token}`
}
})).data;
if (!data.id) throw new Error(ErrorCode.OAUTH_NO_ID);
await checkIdentityAvailability(service, data.id);
await createIdentity({
userId,
identityId: data.id,
type: service,
loginName: data.login
});
} catch (error) {
throw new Error(ErrorCode.OAUTH_ERROR);
}
if (!data || !data.id) throw new Error(ErrorCode.OAUTH_NO_ID);
await checkIdentityAvailability(service, data.id);
await createIdentity({
userId,
identityId: data.id,
type: service,
loginName: data.login
});
return { success: true };
}
};
Expand Down

0 comments on commit a21a3c6

Please sign in to comment.