diff --git a/src/index.ts b/src/index.ts index 531ba1e..5e11a2c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,9 +5,6 @@ import oauthRouter from "./routes/oauth"; import { googleStrategy } from "./auth.config"; import swaggerUi from "swagger-ui-express"; import YAML from "yamljs"; -import swaggerUi from 'swagger-ui-express'; -import YAML from 'yamljs'; - const app = express(); const port = 3000; @@ -15,7 +12,6 @@ passport.use(googleStrategy); passport.serializeUser((user, done) => done(null, user)); passport.deserializeUser((user, done) => done(null, user as Express.User)); - app.use(sessionMiddleware); app.use(passport.initialize()); app.use(passport.session()); @@ -25,8 +21,8 @@ const swaggerDocument = YAML.load("./src/swagger/openapi.yaml"); // Swagger UI 설정 app.use("/docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument)); -app.get('/', (req, res) => { - res.send('Hello World!'); +app.get("/", (req, res) => { + res.send("Hello World!"); }); app.use("/oauth2", oauthRouter); @@ -34,4 +30,3 @@ app.listen(port, () => { console.log(`Server is running at http://localhost:${port}`); console.log(`Swagger UI is available at http://localhost:${port}/docs`); }); - diff --git a/src/swagger/openapi.yaml b/src/swagger/openapi.yaml index 9a1e4d1..12b7976 100644 --- a/src/swagger/openapi.yaml +++ b/src/swagger/openapi.yaml @@ -8,10 +8,69 @@ paths: get: summary: Hello World responses: - '200': + "200": description: 성공 content: text/plain: schema: type: string - example: Hello World! \ No newline at end of file + example: Hello World! + /oauth2/login/google: + get: + summary: Google OAuth2 로그인 시작 + description: Google 로그인 창으로 리디렉션됩니다. + tags: + - Auth + responses: + "302": + description: 구글 로그인 페이지로 리디렉션 + + /oauth2/callback/google: + get: + summary: Google OAuth2 콜백 + description: Google 로그인 후 인증 정보를 처리하는 콜백 URL입니다. + tags: + - Auth + responses: + "302": + description: 로그인 성공 시 리디렉션 + "401": + description: 로그인 실패 + + /oauth2/me: + get: + summary: 로그인된 사용자 정보 조회 + description: 세션을 기반으로 로그인된 사용자의 정보를 반환합니다. + tags: + - Auth + responses: + "200": + description: 로그인된 사용자 정보 + content: + application/json: + schema: + $ref: "#/components/schemas/User" + "401": + description: 로그인되지 않은 상태 + content: + application/json: + schema: + type: object + properties: + message: + type: string + example: Unauthorized +components: + schemas: + User: + type: object + properties: + id: + type: integer + example: 1 + email: + type: string + example: example@gmail.com + name: + type: string + example: 홍길동