From ac0b25fb62dce6ff66658153da73ba814ff056cf Mon Sep 17 00:00:00 2001 From: Rafi Arrafif Date: Thu, 7 Aug 2025 23:07:53 +0700 Subject: [PATCH] :building_construction: separate http and internal service separate between internal and http service due security concern in auth module --- src/modules/auth/controllers/githubCallback.controller.ts | 2 +- src/modules/auth/controllers/githubRequest.controller.ts | 2 +- src/modules/auth/controllers/googleCallback.controller.ts | 2 +- src/modules/auth/controllers/googleRequest.controller.ts | 2 +- .../auth/services/{ => http}/githubCallback.service.ts | 4 ++-- .../auth/services/{ => http}/githubRequest.service.ts | 4 ++-- .../auth/services/{ => http}/googleCallback.service.ts | 8 ++++---- .../auth/services/{ => http}/googleRequest.service.ts | 6 +++--- .../internal/loginIfExistAndCreateIfNot.service.ts | 6 ++++++ 9 files changed, 21 insertions(+), 15 deletions(-) rename src/modules/auth/services/{ => http}/githubCallback.service.ts (84%) rename src/modules/auth/services/{ => http}/githubRequest.service.ts (73%) rename src/modules/auth/services/{ => http}/googleCallback.service.ts (75%) rename src/modules/auth/services/{ => http}/googleRequest.service.ts (75%) create mode 100644 src/modules/auth/services/internal/loginIfExistAndCreateIfNot.service.ts diff --git a/src/modules/auth/controllers/githubCallback.controller.ts b/src/modules/auth/controllers/githubCallback.controller.ts index 5dd524d..6a577da 100644 --- a/src/modules/auth/controllers/githubCallback.controller.ts +++ b/src/modules/auth/controllers/githubCallback.controller.ts @@ -1,6 +1,6 @@ import { Context } from "elysia"; import { returnWriteResponse } from "../../../helpers/callback/httpResponse"; -import { githubCallbackService } from "../services/githubCallback.service"; +import { githubCallbackService } from "../services/http/githubCallback.service"; import { mainErrorHandler } from "../../../helpers/error/handler"; export const githubCallbackController = async ( diff --git a/src/modules/auth/controllers/githubRequest.controller.ts b/src/modules/auth/controllers/githubRequest.controller.ts index 03ea895..9607e42 100644 --- a/src/modules/auth/controllers/githubRequest.controller.ts +++ b/src/modules/auth/controllers/githubRequest.controller.ts @@ -1,6 +1,6 @@ import { Context } from "elysia"; import { returnReadResponse } from "../../../helpers/callback/httpResponse"; -import { githubRequestService } from "../services/githubRequest.service"; +import { githubRequestService } from "../services/http/githubRequest.service"; export const githubRequestController = async (ctx: Context) => { const loginUrl = await githubRequestService(); diff --git a/src/modules/auth/controllers/googleCallback.controller.ts b/src/modules/auth/controllers/googleCallback.controller.ts index 7b0192e..2b1bef4 100644 --- a/src/modules/auth/controllers/googleCallback.controller.ts +++ b/src/modules/auth/controllers/googleCallback.controller.ts @@ -1,7 +1,7 @@ import { Context } from "elysia"; import { returnWriteResponse } from "../../../helpers/callback/httpResponse"; import { mainErrorHandler } from "../../../helpers/error/handler"; -import { googleCallbackService } from "../services/googleCallback.service"; +import { googleCallbackService } from "../services/http/googleCallback.service"; export const googleCallbackController = async ( ctx: Context & { query: { code: string; state: string } } diff --git a/src/modules/auth/controllers/googleRequest.controller.ts b/src/modules/auth/controllers/googleRequest.controller.ts index 5ae0ad1..bba0a05 100644 --- a/src/modules/auth/controllers/googleRequest.controller.ts +++ b/src/modules/auth/controllers/googleRequest.controller.ts @@ -1,6 +1,6 @@ import { Context } from "elysia"; import { mainErrorHandler } from "../../../helpers/error/handler"; -import { googleRequestService } from "../services/googleRequest.service"; +import { googleRequestService } from "../services/http/googleRequest.service"; import { returnReadResponse } from "../../../helpers/callback/httpResponse"; export const googleRequestController = async (ctx: Context) => { diff --git a/src/modules/auth/services/githubCallback.service.ts b/src/modules/auth/services/http/githubCallback.service.ts similarity index 84% rename from src/modules/auth/services/githubCallback.service.ts rename to src/modules/auth/services/http/githubCallback.service.ts index dae5587..63b4f90 100644 --- a/src/modules/auth/services/githubCallback.service.ts +++ b/src/modules/auth/services/http/githubCallback.service.ts @@ -1,5 +1,5 @@ -import { AppError } from "../../../helpers/error/instances/app"; -import { githubProvider } from "../providers/github.provider"; +import { AppError } from "../../../../helpers/error/instances/app"; +import { githubProvider } from "../../providers/github.provider"; export const githubCallbackService = async (code: string) => { try { diff --git a/src/modules/auth/services/githubRequest.service.ts b/src/modules/auth/services/http/githubRequest.service.ts similarity index 73% rename from src/modules/auth/services/githubRequest.service.ts rename to src/modules/auth/services/http/githubRequest.service.ts index a16c365..d19f069 100644 --- a/src/modules/auth/services/githubRequest.service.ts +++ b/src/modules/auth/services/http/githubRequest.service.ts @@ -1,6 +1,6 @@ import * as arctic from "arctic"; -import { githubProvider } from "../providers/github.provider"; -import { AppError } from "../../../helpers/error/instances/app"; +import { githubProvider } from "../../providers/github.provider"; +import { AppError } from "../../../../helpers/error/instances/app"; export const githubRequestService = async () => { try { diff --git a/src/modules/auth/services/googleCallback.service.ts b/src/modules/auth/services/http/googleCallback.service.ts similarity index 75% rename from src/modules/auth/services/googleCallback.service.ts rename to src/modules/auth/services/http/googleCallback.service.ts index 0b46b89..7a4d489 100644 --- a/src/modules/auth/services/googleCallback.service.ts +++ b/src/modules/auth/services/http/googleCallback.service.ts @@ -1,7 +1,7 @@ -import { AppError } from "../../../helpers/error/instances/app"; -import { googleProvider } from "../providers/google.provider"; -import { redis } from "../../../utils/databases/redis/connection"; -import { ErrorForwarder } from "../../../helpers/error/instances/forwarder"; +import { AppError } from "../../../../helpers/error/instances/app"; +import { googleProvider } from "../../providers/google.provider"; +import { redis } from "../../../../utils/databases/redis/connection"; +import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder"; export const googleCallbackService = async (query: { state: string; diff --git a/src/modules/auth/services/googleRequest.service.ts b/src/modules/auth/services/http/googleRequest.service.ts similarity index 75% rename from src/modules/auth/services/googleRequest.service.ts rename to src/modules/auth/services/http/googleRequest.service.ts index 2b4f077..2f58efc 100644 --- a/src/modules/auth/services/googleRequest.service.ts +++ b/src/modules/auth/services/http/googleRequest.service.ts @@ -1,7 +1,7 @@ import * as arctic from "arctic"; -import { AppError } from "../../../helpers/error/instances/app"; -import { googleProvider } from "../providers/google.provider"; -import { redis } from "../../../utils/databases/redis/connection"; +import { AppError } from "../../../../helpers/error/instances/app"; +import { googleProvider } from "../../providers/google.provider"; +import { redis } from "../../../../utils/databases/redis/connection"; export const googleRequestService = async () => { try { diff --git a/src/modules/auth/services/internal/loginIfExistAndCreateIfNot.service.ts b/src/modules/auth/services/internal/loginIfExistAndCreateIfNot.service.ts new file mode 100644 index 0000000..416dc0e --- /dev/null +++ b/src/modules/auth/services/internal/loginIfExistAndCreateIfNot.service.ts @@ -0,0 +1,6 @@ +export const loginIfExistAndCreateIfNotService = () => { + /** + * Create auth session if user already exist, + * create user account and give them auth session if not + */ +};