Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1.2.0 #313

Merged
merged 129 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
ba1383a
refactor: fe internal types
WilleLee Nov 22, 2024
afaf350
refactor: application server broadcast path 추가
JYKIM317 Nov 24, 2024
13c572c
refactor: amf 디코딩 함수 로거 추가
JYKIM317 Nov 24, 2024
294f1af
fix: FFMpeg 480p 출력 제거
JYKIM317 Nov 24, 2024
87c13d3
refactor: mediaServer 스트리밍 이벤트 API 호출 함수 변경
JYKIM317 Nov 24, 2024
db7a0ae
refactor: 소켓 이벤트 분리 및 internalPath 전달
JYKIM317 Nov 24, 2024
fc418c9
feat: 스트림 설정 UI
HongBoogie Nov 24, 2024
a1b8ca4
feat: 방송 정보 설정 가이드 UI
HongBoogie Nov 24, 2024
ab2d557
feat: 방송 시작하기 UI
HongBoogie Nov 24, 2024
21577d7
fix: chatServer 충돌
WilleLee Nov 24, 2024
a380974
chore: 깃헙 이미지 url을 next 설정에 추가
WilleLee Nov 25, 2024
4ad15fd
fix: 채팅 아이템 '님' 표시 제거
WilleLee Nov 25, 2024
f30a654
refactor: 자잘한 수정
HongBoogie Nov 25, 2024
81a9710
feat: 방송 세팅 페이지 api 연결
HongBoogie Nov 25, 2024
52a8f57
feat: 콘텐츠 카테고리 상수 예시
WilleLee Nov 25, 2024
67ebab2
feat: 카테고리 페이지 중 콘텐츠 카테고리 작업 진행
WilleLee Nov 25, 2024
9fe32f1
feat: 카테고리 페이지 내 분위기 카테고리 목록
WilleLee Nov 25, 2024
e768fee
refactor: 카테고리 constants 키 이름 컨벤션 맞추기
WilleLee Nov 25, 2024
7fd2f91
feat: 카테고리 방송 목록 전달 API
JYKIM317 Nov 25, 2024
f81b6ac
test: 카테고리 방송 목록 서비스 테스트
JYKIM317 Nov 25, 2024
e2dd134
style: 카테고리 경로 수정
JYKIM317 Nov 25, 2024
1823d67
feat: stream key 갱신 api 구현
JYKIM317 Nov 25, 2024
927e7bb
feat: 채팅 서버 색상 반환값 추가
JYKIM317 Nov 25, 2024
f545d1b
fix: DI 컨테이너에 DataSource를 주입할 때 문자열 토큰 방식이 아닌 클래스 참조를 사용하도록 변경
zzawang Nov 25, 2024
76e06ec
chore: follow path alias 추가
zzawang Nov 25, 2024
40397c3
feat: 멤버 팔로우/언팔로우 기능 구현
zzawang Nov 25, 2024
cd44b29
feat: 본인 팔로우/언팔로우 금지 기능 추가
zzawang Nov 25, 2024
3f6427f
feat: 사용자의 팔로워/팔로잉 목록 가져오는 API 구현
zzawang Nov 25, 2024
6f3cf54
chore: naver path alias 추가
JYKIM317 Nov 25, 2024
3ecbd9a
refactor: github 로그인 에러처리 추가
JYKIM317 Nov 25, 2024
2935915
style: Github 로그인 관련 상수 리네이밍
JYKIM317 Nov 25, 2024
810c304
style: live mock data 오탈자 수정
JYKIM317 Nov 25, 2024
36f16f1
feat: 네이버 로그인/회원가입 기능 추가
JYKIM317 Nov 25, 2024
8a5e8cd
fix: 비디오 라우팅 개선
WilleLee Nov 25, 2024
648b72a
feat: LiveInfo에서 SSE 통신
WilleLee Nov 25, 2024
dc74c1b
refactor: LiveInfo 각 요소 메모이제이션
WilleLee Nov 25, 2024
704869f
feat: 채팅 컴포넌트 소켓 통신 데이터 타입에 컬러 추가
WilleLee Nov 25, 2024
396f00c
chore: production에서 콘솔 로그 미노출
WilleLee Nov 25, 2024
22883cd
feat: 스튜디오 드롭다운
HongBoogie Nov 26, 2024
00612a6
fix: 팔로워 매핑 key 수정
zzawang Nov 26, 2024
512db0d
test: follow 기능 테스트 추가
zzawang Nov 26, 2024
f5f3f2c
feat: 팔로우-멤버 조인 쿼리 추가
JYKIM317 Nov 26, 2024
17a7ac9
style: User 타입 변경
JYKIM317 Nov 26, 2024
c0267a5
feat: 팔로우 라이브 목록 반환 API 구현
JYKIM317 Nov 26, 2024
64e87f2
feat: 구글 로그인 모듈 세팅
zzawang Nov 26, 2024
d3f6be5
feat: Google authorization code와 access token 가져오는 기능 구현
zzawang Nov 26, 2024
8ed55e8
feat: Google 로그인 API 구현
zzawang Nov 26, 2024
8927315
feat: Google 로그인 모듈 Root 모듈에 추가
zzawang Nov 26, 2024
754bc68
refactor: 회원가입&로그인 로직 중복 코드 개선
zzawang Nov 26, 2024
dda01f6
feat: playlistUrl도 같이 반환하도록 추가
zzawang Nov 26, 2024
222e48b
feat: 콘텐츠 카테고리 상세 페이지
WilleLee Nov 26, 2024
fbf1145
feat: 무드 카테고리 작업 위한 getBroadcastsByMoodCategory
WilleLee Nov 26, 2024
1c7cfd6
feat: 분위기 카테고리 페이지
WilleLee Nov 26, 2024
8bdf60b
chore: 불필요 주석 제거
WilleLee Nov 26, 2024
15c7503
fix: 볼륨 컨트롤러 overflow 관련 픽스
WilleLee Nov 26, 2024
f9c798c
fix: 헤더 및 라이브 섹션 z-index 조정
WilleLee Nov 26, 2024
5e80ddb
feat: naver login
WilleLee Nov 26, 2024
422eb94
feat: 추천 리스트 type 변경
HongBoogie Nov 26, 2024
f518de3
feat: 서랍 comma 함수 적용
HongBoogie Nov 26, 2024
577e6fd
feat: 팔로잉 타입 추가 및 액션 작성
HongBoogie Nov 26, 2024
43bf745
feat: 메인 페이지 팔로잉 채널 UI 작성
HongBoogie Nov 26, 2024
790429c
feat: offline 아이템 추가, Lives 아이템 hover시 border 추가
HongBoogie Nov 26, 2024
aec459a
refactor: 팔로우 Provider 생성
HongBoogie Nov 26, 2024
1972393
refactor: useFollowingLives 분리, provider globalProvider -> main 레이아웃으…
HongBoogie Nov 26, 2024
b02258d
feat: 팔로우 기능
HongBoogie Nov 26, 2024
33fa438
feat: google login
WilleLee Nov 26, 2024
ccb39ed
feat: 로그인 모달 내 버튼들 디자인 커스터마이즈
WilleLee Nov 26, 2024
9ac0f51
chore: loginmodal 내 타입 선언문 위로 이동
WilleLee Nov 26, 2024
e105497
feat: 채팅 개선
WilleLee Nov 26, 2024
1d37682
refactor: LiveSection
WilleLee Nov 27, 2024
1060a65
feat: 리프레시 버튼 회전 이벤트 추가
HongBoogie Nov 27, 2024
f32ece7
feat: 서랍 UI 수정
HongBoogie Nov 27, 2024
820d6f6
fix: 다른 방송 화면 이동 시 채팅 초기화하기
WilleLee Nov 27, 2024
787f910
feat: chat 소켓 연결 에러 핸들링
WilleLee Nov 27, 2024
eef135d
fix: 라이브 프로바이더 개선 진행
WilleLee Nov 27, 2024
4326993
feat: AuthLoading
WilleLee Nov 27, 2024
045efb8
fix: HLS 에러, 로딩, 버퍼링 이벤트 핸들러 추가
WilleLee Nov 27, 2024
49628d3
chore: 불필요 테스트 코드 제거
WilleLee Nov 27, 2024
3d8c47f
fix: 비디오 버퍼링 배경색 조절 및 sharp 설치
WilleLee Nov 27, 2024
c388fb8
feat: 채팅 맨 위에 메세지 노출
WilleLee Nov 27, 2024
1761070
fix: reconnect 시 error 등 초기화하도록
WilleLee Nov 27, 2024
81aa152
chore: error 소켓 이벤트도 constants로 관리
WilleLee Nov 27, 2024
2e7ca57
chore: test 내 불필요한 console.log 제거
WilleLee Nov 27, 2024
8d9809c
feat: 미니 플레이어 상단 버튼 테두리
WilleLee Nov 27, 2024
9e14be5
refactor: 홈 추천 라이브 목록을 서버 컴포넌트로 리팩토링
WilleLee Nov 27, 2024
908267a
feat: not-found.tsx
WilleLee Nov 27, 2024
9f3d7ff
feat: global-error.tsx
WilleLee Nov 27, 2024
44244d0
feat: 팔로우 채널(서랍) UI
HongBoogie Nov 27, 2024
1aaaec6
fix: 페이지 이동간 팔로우가 되어있지 않는 문제
HongBoogie Nov 27, 2024
b960ed4
fix: 서랍에서 로그인 되어있을때만 팔로잉 채널 보이도록 수정
HongBoogie Nov 27, 2024
1d73512
feat: 팔로우 refetch 함수 작성
HongBoogie Nov 27, 2024
f580d28
feat: Toast 작성
HongBoogie Nov 27, 2024
fd330e9
fix: 서랍 배경색 부여, 서랍 Image 상위태그에 width, height 부여
HongBoogie Nov 27, 2024
cc67e07
fix: 캐비넷 숫자 색 수정, 팔로우 목 데이터 버그 수정
WilleLee Nov 28, 2024
6c5e5f5
fix: eventSource.onerror 시 close()만 하도록 수정
WilleLee Nov 28, 2024
5fdd3ed
fix: data가 존재하는 경우에만 refreshInfo 하도록 eventSource.onmessage 수정
WilleLee Nov 28, 2024
b3e5d5b
fix: 복사 기능
HongBoogie Nov 28, 2024
abc124e
fix: followingLivesWrapper에서 로그인 여부 식별
HongBoogie Nov 28, 2024
d0e0e9c
fix: 에러 바운더리 수정
HongBoogie Nov 28, 2024
629f6e7
feat: 스튜디오 비디오 영역 및 채팅 영역
WilleLee Nov 28, 2024
9a8a14f
feat: Github Actions Workflow 작성
JYKIM317 Nov 28, 2024
92232d9
chore: .gitignore 변경
JYKIM317 Nov 28, 2024
8655599
refactor: workflow 수정
JYKIM317 Nov 28, 2024
cbf4a5d
이전과 동일한 커밋
JYKIM317 Nov 28, 2024
a213de5
workflow 인덴트 오류 해결
JYKIM317 Nov 28, 2024
a71bee9
style: 인덴트 변경
JYKIM317 Nov 28, 2024
620d060
fix: deployment.yml 인덴트 오류 해결
JYKIM317 Nov 28, 2024
6ff8157
refactor: 토큰 확인 로직 변경
JYKIM317 Nov 28, 2024
31dd618
README.md 기술스택 추가
JYKIM317 Nov 28, 2024
25a10da
README.md 인프라 업데이트
JYKIM317 Nov 28, 2024
4e72b2d
README.md 인프라 업데이트
JYKIM317 Nov 28, 2024
49910eb
fix: 좁은 서랍 상세보기 min-width 부여
HongBoogie Nov 28, 2024
5f9e535
fix: 멤버의 방송 아이디에서 멤버 아이디를 추출하도록 변경
zzawang Nov 28, 2024
07fe5d5
fix: 비로그인 가드 수정
JYKIM317 Nov 28, 2024
9d8a350
refactor: 방송 mock데이터 고정 이름 할당
JYKIM317 Nov 28, 2024
d2fa366
feat: follow Provider console.log 추가
HongBoogie Nov 28, 2024
ac1da0f
fix: fetchFollowingLives 파라미터 변경
HongBoogie Nov 28, 2024
39e3ce6
fix: removeConsole 부활
HongBoogie Nov 28, 2024
818c5bf
refactor: deployment.yml 스크립트 변경
JYKIM317 Nov 28, 2024
227132c
feat: 팔로우/언팔로우 API 응답 값 추가
zzawang Nov 28, 2024
e11bb68
refactor: unfollow 응답 코드 변경
JYKIM317 Nov 28, 2024
faec4bf
hotfix: 로그인 알러트 없애기
WilleLee Nov 28, 2024
e791337
docs: README(FE) 이미지 수정
HongBoogie Nov 28, 2024
29df12f
fix: body에 formData 추가
HongBoogie Nov 28, 2024
e593a18
기술스택 BE 이미지 업데이트
JYKIM317 Nov 28, 2024
4c56311
fix: 방송 정보 업데이트 API 수정
JYKIM317 Nov 28, 2024
d3348d5
refactor: 방송 정보 업데이트 API 변경
JYKIM317 Nov 28, 2024
bb1219a
refactor: 방송 정보 업데이트 API 변경
JYKIM317 Nov 28, 2024
85d2c8c
refactor: 방송 정보 업데이트 API 변경
JYKIM317 Nov 28, 2024
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
42 changes: 42 additions & 0 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Deployment

on:
push:
branches:
- main

jobs:
funch-deploy:
runs-on: ubuntu-latest
steps:
- name: funch server deploy
env:
SSH_PRIVATE_KEY: ${{ secrets.FUNCH_SSH_KEY }}
SERVER_HOST: ${{ secrets.FUNCH_HOST }}
SERVER_USER: ${{ secrets.FUNCH_USER }}
run: |
echo "${FUNCH_SSH_KEY}" > deploy_key
chmod 600 deploy_key
ssh -i deploy_key ${{ secrets.FUNCH_USER }}@${{ secrets.FUNCH_HOST}}
cd /root/web25-funch
git switch main
git pull origin main
pm2 reload ecosystem.config.js

media-deploy:
runs-on: ubuntu-latest
steps:
- name: media server deploy
env:
SSH_PRIVATE_KEY: ${{ secrets.MEDIA_SSH_KEY }}
SERVER_HOST: ${{ secrets.MEDIA_HOST }}
SERVER_USER: ${{ secrets.MEDIA_USER }}
run: |
echo "${MEDIA_SSH_KEY}" > deploy_key
chmod 600 deploy_key
ssh -i deploy_key ${{ secrets.MEDIA_USER }}@${{ secrets.MEDIA_HOST}}
git switch main
cd /service/web25-funch
git pull origin main
cd mediaServer
pm2 reload ecosystem.config.js
28 changes: 28 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Integration

on:
pull_request:
branches:
- dev
- main

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22.11.0
cache: npm
- name: application server test
run: |
cd applicationServer
npm install
npm test

- name: client test
run: |
cd client
npm install
npm test
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
node_modules/
.github
.env
.gitmessage.txt
logs/
.github/

# client
.env*
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,28 @@
</div>

<br><br>

## 👩🏻‍💻🧑🏻‍💻 기술 스택

<br>


### 공통
<img src="https://firebasestorage.googleapis.com/v0/b/stackticon-81399.appspot.com/o/images%2F1732786637665?alt=media&token=d070c4d4-5a58-4e23-af1d-a7e678d4035b" alt="" />

### FE
<img src="https://firebasestorage.googleapis.com/v0/b/stackticon-81399.appspot.com/o/images%2F1732798743094?alt=media&token=d5b7a4d0-af68-4e54-bc3a-ba25d35a1af1)](https://github.com/msdio/stackticon" alt="" />

### BE
<img src="https://firebasestorage.googleapis.com/v0/b/stackticon-81399.appspot.com/o/images%2F1732804776477?alt=media&token=24f661e1-d9b7-4441-bb1a-640cb838c7b0" alt="" />

<br><br>


## 👩🏻‍💻🧑🏻‍💻 인프라

<br>

![image](https://github.com/user-attachments/assets/8fb4260a-714d-49f7-8057-93d47da0bdb7)


4 changes: 3 additions & 1 deletion applicationServer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@
"^@member/(.*)$": "<rootDir>/src/member/$1",
"^@auth/(.*)$": "<rootDir>/src/auth/core/$1",
"^@github/(.*)$": "<rootDir>/src/auth/github/$1",
"^@naver/(.*)$": "<rootDir>/src/auth/naver/$1",
"^@cookie/(.*)$": "<rootDir>/src/auth/cookie/$1",
"^@authUtil/(.*)$": "<rootDir>/src/auth/util/$1"
"^@authUtil/(.*)$": "<rootDir>/src/auth/util/$1",
"^@follow/(.*)$": "<rootDir>/src/follow/$1"
}
}
}
5 changes: 4 additions & 1 deletion applicationServer/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import { MemberModule } from '@member/member.module';
import { LiveModule } from '@live/live.module';
import { GithubAuthModule } from '@github/github.module';
import { AuthModule } from '@auth/auth.module';
import { FollowModule } from '@follow/follow.module';
import { NaverAuthModule } from '@naver/naver.module';
import { GoogleAuthModule } from '@google/google.module';

dotenv.config();

@Module({
imports: [MemberModule, GithubAuthModule, AuthModule, LiveModule],
imports: [MemberModule, GithubAuthModule, AuthModule, LiveModule, FollowModule, NaverAuthModule, GoogleAuthModule],
})
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
Expand Down
1 change: 1 addition & 0 deletions applicationServer/src/auth/core/auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class NoNeedLoginGuard implements CanActivate {
const request = context.switchToHttp().getRequest();
const accessToken = request.headers['authorization']?.split(' ')[1];

if (accessToken == 'null') return true;
if (accessToken && this.authService.verifyToken(accessToken)) {
throw new HttpException('이미 로그인이 되어있습니다.', HttpStatus.BAD_REQUEST);
}
Expand Down
1 change: 1 addition & 0 deletions applicationServer/src/auth/core/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class AuthService {
}

verifyToken(token: string) {
if (!token) return false;
try {
return this.jwtService.verify(token);
} catch (error) {
Expand Down
11 changes: 1 addition & 10 deletions applicationServer/src/auth/github/github.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class GithubAuthController {
const githubAccessToken = await this.githubAuthService.getAccessToken(code);
const { id, avatar_url } = await this.githubAuthService.getUserInfo(githubAccessToken);

const member = await this.findOrRegisterMember(`Github@${id}`, avatar_url);
const member = await this.memberService.findOrRegisterMember(`Github@${id}`, avatar_url);
const accessToken = this.authService.generateAccessToken(member.id);
const refreshToken = this.authService.generateRefreshToken(member.id);

Expand All @@ -31,15 +31,6 @@ class GithubAuthController {

return { accessToken, name: member.name, profile_image: member.profile_image, broadcast_id: member.broadcast_id };
}

private async findOrRegisterMember(memberId: string, avatar_url: string) {
const member = await this.memberService.findOneMemberWithCondition({ id: memberId });
if (!member) {
const newMember = await this.memberService.register(memberId, avatar_url);
return newMember;
}
return member;
}
}

export { GithubAuthController };
34 changes: 21 additions & 13 deletions applicationServer/src/auth/github/github.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable, HttpException, HttpStatus } from '@nestjs/common';
import axios from 'axios';
import { ACCESS_TOKEN_URL, APPLICATION_JSON, RESOURCE_URL } from '@src/constants';
import { GITHUB_ACCESS_TOKEN_URL, APPLICATION_JSON, GITHUB_RESOURCE_URL } from '@src/constants';

@Injectable()
class GithubAuthService {
Expand All @@ -9,14 +9,18 @@ class GithubAuthService {
async getAccessToken(code: string): Promise<string> {
const request = {
code,
client_id: process.env.CLIENT_ID,
client_secret: process.env.CLIENT_SECRETS,
client_id: process.env.GITHUB_CLIENT_ID,
client_secret: process.env.GITHUB_CLIENT_SECRET,
};
const response = await axios.post(ACCESS_TOKEN_URL, request, {
headers: {
accept: APPLICATION_JSON,
},
});
const response = await axios
.post(GITHUB_ACCESS_TOKEN_URL, request, {
headers: {
accept: APPLICATION_JSON,
},
})
.catch(() => {
throw new HttpException('Github AccessToken 가져오기 실패', HttpStatus.UNAUTHORIZED);
});

if (response.data.error) {
throw new HttpException('Github AccessToken 가져오기 실패', HttpStatus.UNAUTHORIZED);
Expand All @@ -25,11 +29,15 @@ class GithubAuthService {
}

async getUserInfo(accessToken: string) {
const { data } = await axios.get(RESOURCE_URL, {
headers: {
Authorization: `token ${accessToken}`,
},
});
const { data } = await axios
.get(GITHUB_RESOURCE_URL, {
headers: {
Authorization: `Bearer ${accessToken}`,
},
})
.catch(() => {
throw new HttpException('Github 유저 정보 가져오기 실패', HttpStatus.FAILED_DEPENDENCY);
});

return data;
}
Expand Down
36 changes: 36 additions & 0 deletions applicationServer/src/auth/google/google.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Controller, Post, Body, Res, UseGuards } from '@nestjs/common';
import { Response } from 'express';
import { MemberService } from '@src/member/member.service';
import { GoogleAuthService } from '@google/google.service';
import { AuthService } from '@auth/auth.service';
import { CookieService } from '@cookie/cookie.service';
import { NoNeedLoginGuard } from '@auth/auth.guard';
import { REFRESH_TOKEN } from '@src/constants';

@Controller('auth/google')
class GoogleAuthController {
constructor(
private readonly googleAuthService: GoogleAuthService,
private readonly memberService: MemberService,
private readonly authService: AuthService,
private readonly cookieService: CookieService,
) {}

@Post('/callback')
@UseGuards(NoNeedLoginGuard)
async getAccessToken(@Body('code') code: string, @Res({ passthrough: true }) res: Response) {
const googleAccessToken = await this.googleAuthService.getAccessToken(decodeURIComponent(code));
const { id, picture } = await this.googleAuthService.getUserInfo(googleAccessToken);

const member = await this.memberService.findOrRegisterMember(`Google@${id}`, picture);
const accessToken = this.authService.generateAccessToken(member.id);
const refreshToken = this.authService.generateRefreshToken(member.id);

this.authService.saveRefreshToken(member.id, refreshToken);
this.cookieService.setCookie(res, REFRESH_TOKEN, refreshToken);

return { accessToken, name: member.name, profile_image: member.profile_image, broadcast_id: member.broadcast_id };
}
}

export { GoogleAuthController };
14 changes: 14 additions & 0 deletions applicationServer/src/auth/google/google.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Module } from '@nestjs/common';
import { GoogleAuthController } from '@google/google.controller';
import { GoogleAuthService } from '@google/google.service';
import { DatabaseModule } from '@src/database/database.module';
import { MemberModule } from '@src/member/member.module';
import { AuthModule } from '@auth/auth.module';
import { CookieModule } from '@cookie/cookie.module';

@Module({
imports: [DatabaseModule, MemberModule, AuthModule, CookieModule],
controllers: [GoogleAuthController],
providers: [GoogleAuthService],
})
export class GoogleAuthModule {}
48 changes: 48 additions & 0 deletions applicationServer/src/auth/google/google.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Injectable, HttpException, HttpStatus } from '@nestjs/common';
import axios from 'axios';
import { AUTHORIZATION_CODE, GOOGLE_ACCESS_TOKEN_URL, APPLICATION_JSON, GOOGLE_RESOURCE_URL } from '@src/constants';

@Injectable()
class GoogleAuthService {
constructor() {}

async getAccessToken(code: string): Promise<string> {
const request = {
code,
client_id: process.env.GOOGLE_CLIENT_ID,
client_secret: process.env.GOOGLE_CLIENT_SECRET,
redirect_uri: process.env.GOOGLE_REDIRECT_URL,
grant_type: AUTHORIZATION_CODE,
};

const response = await axios
.post(GOOGLE_ACCESS_TOKEN_URL, request, {
headers: {
accept: APPLICATION_JSON,
},
})
.catch(() => {
throw new HttpException('Google AccessToken 가져오기 실패', HttpStatus.UNAUTHORIZED);
});

if (response.data.error) {
throw new HttpException('Google AccessToken 가져오기 실패', HttpStatus.UNAUTHORIZED);
}
return response.data.access_token;
}

async getUserInfo(accessToken: string) {
const { data } = await axios
.get(GOOGLE_RESOURCE_URL, {
headers: {
Authorization: `Bearer ${accessToken}`,
},
})
.catch(() => {
throw new HttpException('Google 유저 정보 가져오기 실패', HttpStatus.FAILED_DEPENDENCY);
});
return data;
}
}

export { GoogleAuthService };
39 changes: 39 additions & 0 deletions applicationServer/src/auth/naver/naver.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Controller, Post, Body, Res, UseGuards } from '@nestjs/common';
import { Response } from 'express';
import { MemberService } from '@src/member/member.service';
import { NaverAuthService } from '@naver/naver.service';
import { AuthService } from '@auth/auth.service';
import { CookieService } from '@cookie/cookie.service';
import { NoNeedLoginGuard } from '@auth/auth.guard';
import { REFRESH_TOKEN } from '@src/constants';

@Controller('auth/naver')
class NaverAuthController {
constructor(
private readonly naverAuthService: NaverAuthService,
private readonly memberService: MemberService,
private readonly authService: AuthService,
private readonly cookieService: CookieService,
) {}

@Post('/callback')
@UseGuards(NoNeedLoginGuard)
async getAccessToken(
@Body('code') code: string,
@Body('state') state: string,
@Res({ passthrough: true }) res: Response,
) {
const naverAccessToken = await this.naverAuthService.getAccessToken(code, state);
const { id } = await this.naverAuthService.getUserInfo(naverAccessToken);
const member = await this.memberService.findOrRegisterMember(`Naver@${id}`);
const accessToken = this.authService.generateAccessToken(member.id);
const refreshToken = this.authService.generateRefreshToken(member.id);

this.authService.saveRefreshToken(member.id, refreshToken);
this.cookieService.setCookie(res, REFRESH_TOKEN, refreshToken);

return { accessToken, name: member.name, profile_image: member.profile_image, broadcast_id: member.broadcast_id };
}
}

export { NaverAuthController };
14 changes: 14 additions & 0 deletions applicationServer/src/auth/naver/naver.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Module } from '@nestjs/common';
import { NaverAuthController } from '@naver/naver.controller';
import { NaverAuthService } from '@naver/naver.service';
import { DatabaseModule } from '@src/database/database.module';
import { MemberModule } from '@src/member/member.module';
import { AuthModule } from '@auth/auth.module';
import { CookieModule } from '@cookie/cookie.module';

@Module({
imports: [DatabaseModule, MemberModule, AuthModule, CookieModule],
controllers: [NaverAuthController],
providers: [NaverAuthService],
})
export class NaverAuthModule {}
Loading
Loading