✨ 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:
@ -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);
|
||||
}
|
||||
};
|
||||
@ -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)
|
||||
|
||||
@ -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;
|
||||
};
|
||||
Reference in New Issue
Block a user