🏗️ separate http and internal service

separate between internal and http service due security concern in auth module
This commit is contained in:
Rafi Arrafif
2025-08-07 23:07:53 +07:00
parent 0d71710b14
commit ac0b25fb62
9 changed files with 21 additions and 15 deletions

View File

@ -0,0 +1,27 @@
import { AppError } from "../../../../helpers/error/instances/app";
import { githubProvider } from "../../providers/github.provider";
export const githubCallbackService = async (code: string) => {
try {
const github = githubProvider();
const tokens = await github.validateAuthorizationCode(code);
const accessToken = tokens.accessToken();
const userdata = await fetch("https://api.github.com/user", {
headers: {
Authorization: `Bearer ${accessToken}`,
},
});
const useremail = await fetch("https://api.github.com/user/emails", {
headers: {
Authorization: `Bearer ${accessToken}`,
},
});
return {
userdata: await userdata.json(),
useremail: await useremail.json(),
};
} catch (error) {
return new AppError(500, "Authentication service error", error);
}
};