Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ 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;
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());
Expand All @@ -25,13 +21,12 @@ 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);

app.listen(port, () => {
console.log(`Server is running at http://localhost:${port}`);
console.log(`Swagger UI is available at http://localhost:${port}/docs`);
});

63 changes: 61 additions & 2 deletions src/swagger/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,69 @@ paths:
get:
summary: Hello World
responses:
'200':
"200":
description: 성공
content:
text/plain:
schema:
type: string
example: Hello World!
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: [email protected]
name:
type: string
example: 홍길동