💡 (docs-code) add code documentation

This commit is contained in:
Rafi Arrafif
2025-09-08 22:53:10 +07:00
parent a2a46ec933
commit cd8a0490c4
2 changed files with 9 additions and 0 deletions

View File

@ -9,9 +9,14 @@ export const githubCallbackService = async (
userHeaderInfo: UserHeaderInformation userHeaderInfo: UserHeaderInformation
) => { ) => {
try { try {
// Initialize GitHub provider
const github = githubProvider(query.callbackURI); const github = githubProvider(query.callbackURI);
// Validate the authorization code and get tokens
const tokens = await github.validateAuthorizationCode(query.code); const tokens = await github.validateAuthorizationCode(query.code);
const accessToken = tokens.accessToken(); const accessToken = tokens.accessToken();
// Fetch user data and email from GitHub API
const userdata = await fetch("https://api.github.com/user", { const userdata = await fetch("https://api.github.com/user", {
headers: { headers: {
Authorization: `Bearer ${accessToken}`, Authorization: `Bearer ${accessToken}`,
@ -23,11 +28,13 @@ export const githubCallbackService = async (
}, },
}); });
// Parse the user data and email responses into JSON, then combine them into a single payload
const userPayload: GithubCallbackUserData = { const userPayload: GithubCallbackUserData = {
user_data: await userdata.json(), user_data: await userdata.json(),
user_email: await useremail.json(), user_email: await useremail.json(),
}; };
// Provision or authenticate the user in the system
return await OAuthUserProvisionService( return await OAuthUserProvisionService(
{ {
provider: "github", provider: "github",

View File

@ -43,8 +43,10 @@ export const googleCallbackService = async (
} }
); );
// parse the user data response
const userData = (await response.json()) as GoogleCallbackUserData; const userData = (await response.json()) as GoogleCallbackUserData;
// Provision or authenticate the user in the system
return await OAuthUserProvisionService( return await OAuthUserProvisionService(
{ {
provider: "google", provider: "google",