👔 create list for oauth providers
create list and endpoint to see avaiable oauth providers.
This commit is contained in:
20
src/config/oauthProvider.ts
Normal file
20
src/config/oauthProvider.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
export const getOauthProviders = () => {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
name: "google",
|
||||||
|
icon: "logos:google-icon",
|
||||||
|
req_endpoint: "auth/github",
|
||||||
|
client_id: process.env.GOOGLE_CLIENT_ID,
|
||||||
|
client_secret: process.env.GOOGLE_CLIENT_SECRET,
|
||||||
|
client_callback: "auth/google/callback",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "github",
|
||||||
|
icon: "logos:github-icon",
|
||||||
|
req_endpoint: "auth/github",
|
||||||
|
client_id: process.env.GITHUB_CLIENT_ID,
|
||||||
|
client_secret: process.env.GITHUB_CLIENT_SECRET,
|
||||||
|
client_callback: "auth/github/callback",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
};
|
||||||
11
src/modules/auth/controllers/getOauthProviders.controller.ts
Normal file
11
src/modules/auth/controllers/getOauthProviders.controller.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { Context } from "elysia";
|
||||||
|
import { mainErrorHandler } from "../../../helpers/error/handler";
|
||||||
|
import { getOauthProvidersService } from "../services/http/getOauthProviders.service";
|
||||||
|
|
||||||
|
export const getOauthProvidersController = (ctx: Context) => {
|
||||||
|
try {
|
||||||
|
return getOauthProvidersService();
|
||||||
|
} catch (error) {
|
||||||
|
return mainErrorHandler(ctx.set, error);
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -3,8 +3,10 @@ import { githubRequestController } from "./controllers/githubRequest.controller"
|
|||||||
import { githubCallbackController } from "./controllers/githubCallback.controller";
|
import { githubCallbackController } from "./controllers/githubCallback.controller";
|
||||||
import { googleRequestController } from "./controllers/googleRequest.controller";
|
import { googleRequestController } from "./controllers/googleRequest.controller";
|
||||||
import { googleCallbackController } from "./controllers/googleCallback.controller";
|
import { googleCallbackController } from "./controllers/googleCallback.controller";
|
||||||
|
import { getOauthProvidersController } from "./controllers/getOauthProviders.controller";
|
||||||
|
|
||||||
export const authModule = new Elysia({ prefix: "/auth" })
|
export const authModule = new Elysia({ prefix: "/auth" })
|
||||||
|
.get("/providers", getOauthProvidersController)
|
||||||
.get("/github", githubRequestController)
|
.get("/github", githubRequestController)
|
||||||
.get("/github/callback", githubCallbackController)
|
.get("/github/callback", githubCallbackController)
|
||||||
.get("/google", googleRequestController)
|
.get("/google", googleRequestController)
|
||||||
|
|||||||
16
src/modules/auth/services/http/getOauthProviders.service.ts
Normal file
16
src/modules/auth/services/http/getOauthProviders.service.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { getOauthProviders } from "../../../../config/oauthProvider";
|
||||||
|
import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder";
|
||||||
|
|
||||||
|
export const getOauthProvidersService = () => {
|
||||||
|
try {
|
||||||
|
const listProviders = getOauthProviders();
|
||||||
|
|
||||||
|
return listProviders.map(({ name, icon, req_endpoint }) => ({
|
||||||
|
name,
|
||||||
|
icon,
|
||||||
|
req_endpoint,
|
||||||
|
}));
|
||||||
|
} catch (error) {
|
||||||
|
ErrorForwarder(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user