feat: add new route to get client callback

This new route serves to find the client callback after successfully logging in from the provider page. This is done so that the callback becomes more flexible and can be changed at any time.
This commit is contained in:
Rafi Arrafif
2026-01-08 17:22:05 +07:00
parent d8e8ec3fa7
commit c1d5d1692b
4 changed files with 39 additions and 1 deletions

View File

@ -0,0 +1,22 @@
import { Context } from "elysia";
import { mainErrorHandler } from "../../../helpers/error/handler";
import { getCallbackProviderUrlService } from "../services/http/getCallbackProviderUrl.service";
import { returnReadResponse } from "../../../helpers/callback/httpResponse";
export const getCallbackProviderUrlController = async (
ctx: Context & { params: { name: string } }
) => {
try {
const callbackProviderUrl = await getCallbackProviderUrlService(
ctx.params.name
);
return returnReadResponse(
ctx.set,
200,
"The callback URL on the provider has been found.",
callbackProviderUrl
);
} catch (error) {
return mainErrorHandler(ctx.set, error);
}
};

View File

@ -4,9 +4,11 @@ import { githubCallbackController } from "./controllers/githubCallback.controlle
import { googleRequestController } from "./controllers/googleRequest.controller";
import { googleCallbackController } from "./controllers/googleCallback.controller";
import { getOauthProvidersController } from "./controllers/getOauthProviders.controller";
import { getCallbackProviderUrlController } from "./controllers/getCallbackProviderUrl.controller";
export const authModule = new Elysia({ prefix: "/auth" })
.get("/providers", getOauthProvidersController)
.get("/providers/:name/callback", getCallbackProviderUrlController)
.get("/github", githubRequestController)
.get("/github/callback", githubCallbackController)
.get("/google", googleRequestController)

View File

@ -0,0 +1,14 @@
import { getOauthProviders } from "../../../../config/oauthProvider";
import { AppError } from "../../../../helpers/error/instances/app";
export const getCallbackProviderUrlService = async (providerName: string) => {
const callbackUrl = getOauthProviders().find(
(provider) => provider.name === providerName
)?.client_callback;
if (!callbackUrl) {
throw new AppError(404, "The specified provider does not exist.");
}
return callbackUrl;
};

View File

@ -25,7 +25,7 @@
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
/* Modules */
"module": "Node16" /* Specify what module code is generated. */,
"module": "NodeNext" /* Specify what module code is generated. */,
// "rootDir": "./", /* Specify the root folder within your source files. */
"moduleResolution": "node16" /* Specify how TypeScript looks up a file from a given module specifier. */,
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */