From 1d57a5eacd3f319e62a52493db8ddae3ad249006 Mon Sep 17 00:00:00 2001 From: Gon Kim Date: Thu, 17 Nov 2022 19:27:04 +0900 Subject: [PATCH 001/149] =?UTF-8?q?feat:=20[BE]=20nginx=EB=A5=BC=20?= =?UTF-8?q?=EC=9D=B4=EC=9A=A9=ED=95=9C=20=EB=A6=AC=EC=95=A1=ED=8A=B8=20?= =?UTF-8?q?=EB=B9=8C=EB=93=9C=ED=8C=8C=EC=9D=BC=20=EB=B0=B0=ED=8F=AC,=20do?= =?UTF-8?q?cker-compose=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 8 ++ packages/nginx/configs/conf.d/default.conf | 12 +++ packages/nginx/configs/fastcgi_params | 25 ++++++ packages/nginx/configs/mime.types | 99 ++++++++++++++++++++++ packages/nginx/configs/modules | 1 + packages/nginx/configs/nginx.conf | 33 ++++++++ packages/nginx/configs/scgi_params | 17 ++++ packages/nginx/configs/uwsgi_params | 17 ++++ packages/nginx/dockerfile | 10 +++ 9 files changed, 222 insertions(+) create mode 100644 packages/nginx/configs/conf.d/default.conf create mode 100644 packages/nginx/configs/fastcgi_params create mode 100644 packages/nginx/configs/mime.types create mode 120000 packages/nginx/configs/modules create mode 100644 packages/nginx/configs/nginx.conf create mode 100644 packages/nginx/configs/scgi_params create mode 100644 packages/nginx/configs/uwsgi_params create mode 100644 packages/nginx/dockerfile diff --git a/docker-compose.yml b/docker-compose.yml index efeb14a..dabd06f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,6 +24,14 @@ services: command: - --character-set-server=utf8mb4 - --collation-server=utf8mb4_unicode_ci + nginx: + container_name: 'nginx' + build: ./packages/nginx + ports: + - 3000:3000 + volumes: + - ./packages/nginx/configs:/etc/nginx + - ./packages/client/build:/usr/share/buddah-client volumes: mysql-volume: diff --git a/packages/nginx/configs/conf.d/default.conf b/packages/nginx/configs/conf.d/default.conf new file mode 100644 index 0000000..0fd6f46 --- /dev/null +++ b/packages/nginx/configs/conf.d/default.conf @@ -0,0 +1,12 @@ +server { + listen 3000; + + access_log /var/log/nginx/access.log main_log_format; + + location / { + root /usr/share/buddah-client; + index index.html index.htm; + try_files $uri $uri/ /index.html; + } +} + diff --git a/packages/nginx/configs/fastcgi_params b/packages/nginx/configs/fastcgi_params new file mode 100644 index 0000000..28decb9 --- /dev/null +++ b/packages/nginx/configs/fastcgi_params @@ -0,0 +1,25 @@ + +fastcgi_param QUERY_STRING $query_string; +fastcgi_param REQUEST_METHOD $request_method; +fastcgi_param CONTENT_TYPE $content_type; +fastcgi_param CONTENT_LENGTH $content_length; + +fastcgi_param SCRIPT_NAME $fastcgi_script_name; +fastcgi_param REQUEST_URI $request_uri; +fastcgi_param DOCUMENT_URI $document_uri; +fastcgi_param DOCUMENT_ROOT $document_root; +fastcgi_param SERVER_PROTOCOL $server_protocol; +fastcgi_param REQUEST_SCHEME $scheme; +fastcgi_param HTTPS $https if_not_empty; + +fastcgi_param GATEWAY_INTERFACE CGI/1.1; +fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; + +fastcgi_param REMOTE_ADDR $remote_addr; +fastcgi_param REMOTE_PORT $remote_port; +fastcgi_param SERVER_ADDR $server_addr; +fastcgi_param SERVER_PORT $server_port; +fastcgi_param SERVER_NAME $server_name; + +# PHP only, required if PHP was built with --enable-force-cgi-redirect +fastcgi_param REDIRECT_STATUS 200; diff --git a/packages/nginx/configs/mime.types b/packages/nginx/configs/mime.types new file mode 100644 index 0000000..1c00d70 --- /dev/null +++ b/packages/nginx/configs/mime.types @@ -0,0 +1,99 @@ + +types { + text/html html htm shtml; + text/css css; + text/xml xml; + image/gif gif; + image/jpeg jpeg jpg; + application/javascript js; + application/atom+xml atom; + application/rss+xml rss; + + text/mathml mml; + text/plain txt; + text/vnd.sun.j2me.app-descriptor jad; + text/vnd.wap.wml wml; + text/x-component htc; + + image/avif avif; + image/png png; + image/svg+xml svg svgz; + image/tiff tif tiff; + image/vnd.wap.wbmp wbmp; + image/webp webp; + image/x-icon ico; + image/x-jng jng; + image/x-ms-bmp bmp; + + font/woff woff; + font/woff2 woff2; + + application/java-archive jar war ear; + application/json json; + application/mac-binhex40 hqx; + application/msword doc; + application/pdf pdf; + application/postscript ps eps ai; + application/rtf rtf; + application/vnd.apple.mpegurl m3u8; + application/vnd.google-earth.kml+xml kml; + application/vnd.google-earth.kmz kmz; + application/vnd.ms-excel xls; + application/vnd.ms-fontobject eot; + application/vnd.ms-powerpoint ppt; + application/vnd.oasis.opendocument.graphics odg; + application/vnd.oasis.opendocument.presentation odp; + application/vnd.oasis.opendocument.spreadsheet ods; + application/vnd.oasis.opendocument.text odt; + application/vnd.openxmlformats-officedocument.presentationml.presentation + pptx; + application/vnd.openxmlformats-officedocument.spreadsheetml.sheet + xlsx; + application/vnd.openxmlformats-officedocument.wordprocessingml.document + docx; + application/vnd.wap.wmlc wmlc; + application/wasm wasm; + application/x-7z-compressed 7z; + application/x-cocoa cco; + application/x-java-archive-diff jardiff; + application/x-java-jnlp-file jnlp; + application/x-makeself run; + application/x-perl pl pm; + application/x-pilot prc pdb; + application/x-rar-compressed rar; + application/x-redhat-package-manager rpm; + application/x-sea sea; + application/x-shockwave-flash swf; + application/x-stuffit sit; + application/x-tcl tcl tk; + application/x-x509-ca-cert der pem crt; + application/x-xpinstall xpi; + application/xhtml+xml xhtml; + application/xspf+xml xspf; + application/zip zip; + + application/octet-stream bin exe dll; + application/octet-stream deb; + application/octet-stream dmg; + application/octet-stream iso img; + application/octet-stream msi msp msm; + + audio/midi mid midi kar; + audio/mpeg mp3; + audio/ogg ogg; + audio/x-m4a m4a; + audio/x-realaudio ra; + + video/3gpp 3gpp 3gp; + video/mp2t ts; + video/mp4 mp4; + video/mpeg mpeg mpg; + video/quicktime mov; + video/webm webm; + video/x-flv flv; + video/x-m4v m4v; + video/x-mng mng; + video/x-ms-asf asx asf; + video/x-ms-wmv wmv; + video/x-msvideo avi; +} diff --git a/packages/nginx/configs/modules b/packages/nginx/configs/modules new file mode 120000 index 0000000..4b9b33f --- /dev/null +++ b/packages/nginx/configs/modules @@ -0,0 +1 @@ +/usr/lib/nginx/modules \ No newline at end of file diff --git a/packages/nginx/configs/nginx.conf b/packages/nginx/configs/nginx.conf new file mode 100644 index 0000000..45e3fd2 --- /dev/null +++ b/packages/nginx/configs/nginx.conf @@ -0,0 +1,33 @@ + +user nginx; +worker_processes auto; + +pid /var/run/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main_log_format '$remote_addr - $remote_user [$time_local] ' + '"$request" $status $body_bytes_sent ' + '"$http_referer" "$http_user_agent" "$http_x_forwarded_for"'; + + access_log off; + log_not_found off; + + error_log /var/log/nginx/error.log crit; + + sendfile on; + + keepalive_timeout 65; + + gzip on; + + include /etc/nginx/conf.d/*.conf; +} diff --git a/packages/nginx/configs/scgi_params b/packages/nginx/configs/scgi_params new file mode 100644 index 0000000..6d4ce4f --- /dev/null +++ b/packages/nginx/configs/scgi_params @@ -0,0 +1,17 @@ + +scgi_param REQUEST_METHOD $request_method; +scgi_param REQUEST_URI $request_uri; +scgi_param QUERY_STRING $query_string; +scgi_param CONTENT_TYPE $content_type; + +scgi_param DOCUMENT_URI $document_uri; +scgi_param DOCUMENT_ROOT $document_root; +scgi_param SCGI 1; +scgi_param SERVER_PROTOCOL $server_protocol; +scgi_param REQUEST_SCHEME $scheme; +scgi_param HTTPS $https if_not_empty; + +scgi_param REMOTE_ADDR $remote_addr; +scgi_param REMOTE_PORT $remote_port; +scgi_param SERVER_PORT $server_port; +scgi_param SERVER_NAME $server_name; diff --git a/packages/nginx/configs/uwsgi_params b/packages/nginx/configs/uwsgi_params new file mode 100644 index 0000000..09c732c --- /dev/null +++ b/packages/nginx/configs/uwsgi_params @@ -0,0 +1,17 @@ + +uwsgi_param QUERY_STRING $query_string; +uwsgi_param REQUEST_METHOD $request_method; +uwsgi_param CONTENT_TYPE $content_type; +uwsgi_param CONTENT_LENGTH $content_length; + +uwsgi_param REQUEST_URI $request_uri; +uwsgi_param PATH_INFO $document_uri; +uwsgi_param DOCUMENT_ROOT $document_root; +uwsgi_param SERVER_PROTOCOL $server_protocol; +uwsgi_param REQUEST_SCHEME $scheme; +uwsgi_param HTTPS $https if_not_empty; + +uwsgi_param REMOTE_ADDR $remote_addr; +uwsgi_param REMOTE_PORT $remote_port; +uwsgi_param SERVER_PORT $server_port; +uwsgi_param SERVER_NAME $server_name; diff --git a/packages/nginx/dockerfile b/packages/nginx/dockerfile new file mode 100644 index 0000000..5a11139 --- /dev/null +++ b/packages/nginx/dockerfile @@ -0,0 +1,10 @@ +FROM nginx + +# COPY ./nginx/nginx.conf /etc/nginx/nginx.conf +# COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf + +WORKDIR /usr/share +RUN mkdir buddah-client + +# COPY ./client/build/index.html /usr/share/buddah-client +# COPY ./client/build/static /usr/share/buddah-client/static \ No newline at end of file From 895ffbb957b774f36c1ae0e077e60c3d3ac0bd0b Mon Sep 17 00:00:00 2001 From: Gon Kim Date: Thu, 17 Nov 2022 23:07:05 +0900 Subject: [PATCH 002/149] =?UTF-8?q?chore:=20[FE]=20build=20=ED=8F=B4?= =?UTF-8?q?=EB=8D=94=20gitignore=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 418d151..ace12c1 100644 --- a/.gitignore +++ b/.gitignore @@ -181,6 +181,7 @@ dist node_modules package-lock.json +build *.sublime* From e7665e3ba12337db7ff822389ae359978c7ee930 Mon Sep 17 00:00:00 2001 From: Gon Kim Date: Thu, 17 Nov 2022 23:09:24 +0900 Subject: [PATCH 003/149] =?UTF-8?q?fix:=20[BE]=20client=20uri=20=ED=99=98?= =?UTF-8?q?=EA=B2=BD=20=EB=B3=80=EC=88=98=ED=99=94,=20=EB=A6=AC=EB=AA=A8?= =?UTF-8?q?=ED=8A=B8=20=EC=84=9C=EB=B2=84=20ip=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/server/src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/main.ts b/packages/server/src/main.ts index fe9df10..d24a37b 100644 --- a/packages/server/src/main.ts +++ b/packages/server/src/main.ts @@ -5,7 +5,7 @@ import session from 'express-session'; async function bootstrap() { const app = await NestFactory.create(AppModule); app.enableCors({ - origin: 'http://localhost:3000', + origin: process.env.CLIENT_URI, credentials: true, }); app.use( From a37b1424d8215a807b2f5fdb057059f345d27e86 Mon Sep 17 00:00:00 2001 From: Gon Kim Date: Thu, 17 Nov 2022 23:19:26 +0900 Subject: [PATCH 004/149] =?UTF-8?q?fix:=20service=EC=97=90=20=ED=95=98?= =?UTF-8?q?=EB=93=9C=EC=BD=94=EB=94=A9=EB=90=9C=20client=20uri=20=ED=99=98?= =?UTF-8?q?=EA=B2=BD=20=EB=B3=80=EC=88=98=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/server/src/auth/auth.service.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/server/src/auth/auth.service.ts b/packages/server/src/auth/auth.service.ts index a5e7425..38fbd14 100644 --- a/packages/server/src/auth/auth.service.ts +++ b/packages/server/src/auth/auth.service.ts @@ -47,7 +47,8 @@ export class AuthService { async _getTokens(code: string, state: string) { const redirectURI = encodeURI( // 'http://localhost:8080/api/v1/user/naver-oauth' - 'http://localhost:3000' + process.env.CLIENT_URI + // 'http://localhost:3000' ); const clientId = process.env.CLIENT_ID; From ff3091491cc084bb5d378f4b4bae63f24fb21d28 Mon Sep 17 00:00:00 2001 From: jinoo7099 Date: Fri, 18 Nov 2022 00:49:10 +0900 Subject: [PATCH 005/149] =?UTF-8?q?feat:=20[BE]=20docker=20=EC=8B=A4?= =?UTF-8?q?=ED=96=89=ED=99=98=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=9D=BC=20?= =?UTF-8?q?=ED=99=98=EA=B2=BD=EB=B3=80=EC=88=98=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MYSQL_HOST를 mysql container의 호스트 주소로 자동으로 매핑되도록 설정 --- docker-compose.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index efeb14a..c34467f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,6 +9,8 @@ services: - ./packages/server/.prod.env ports: - 8080:8080 + environment: + MYSQL_HOST: mysql depends_on: - mysql @@ -27,5 +29,5 @@ services: volumes: mysql-volume: - external: - name: mysql-volume + external: true + name: mysql-volume From 9d742693e333152b9e69406959ef299ee3444c74 Mon Sep 17 00:00:00 2001 From: Gon Kim Date: Sat, 19 Nov 2022 14:20:09 +0900 Subject: [PATCH 006/149] =?UTF-8?q?feat:=20[BE]=20fe=20dev=20ci=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=9A=A9=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/fe-dev-ci.yml | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/fe-dev-ci.yml diff --git a/.github/workflows/fe-dev-ci.yml b/.github/workflows/fe-dev-ci.yml new file mode 100644 index 0000000..be59d43 --- /dev/null +++ b/.github/workflows/fe-dev-ci.yml @@ -0,0 +1,38 @@ +name: Frontend dev ci + +on: + push: + branches: [feat/be/front-ci] + # pull_request: + # branches: [dev] + +jobs: + ci: + runs-on: ubuntu-latest + defaults: + run: + working-directory: './packages/client' + + # job + strategy: + # matrix 아래에는 matrix.xxx와 같은 방법으로 참조 가능한 변수를 선언 + # job은 각각의 변수들을 가지고 combinations를 만들어 실행시킨다. + matrix: + node-version: [18.x] + + steps: + - name: checkout to the branch + uses: actions/checkout@v3 + + - name: node set-up + uses: actions/setup-node@v3 + with: + node-version: 18.6.0 + cache: 'npm' + cache-dependency-path: ./packages/client/package-lock.json + + - name: Install dependencies + run: npm ci + + - name: Test + run: npm run test From 0ceb5730bd4f6029f3ecde11a688b2f710ea9ade Mon Sep 17 00:00:00 2001 From: Gon Kim <87866588+Gonnnnn@users.noreply.github.com> Date: Sat, 19 Nov 2022 14:33:02 +0900 Subject: [PATCH 007/149] =?UTF-8?q?dependency=20cache=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/fe-dev-ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/fe-dev-ci.yml b/.github/workflows/fe-dev-ci.yml index be59d43..b3d3c6b 100644 --- a/.github/workflows/fe-dev-ci.yml +++ b/.github/workflows/fe-dev-ci.yml @@ -28,8 +28,6 @@ jobs: uses: actions/setup-node@v3 with: node-version: 18.6.0 - cache: 'npm' - cache-dependency-path: ./packages/client/package-lock.json - name: Install dependencies run: npm ci From c894eb064c47543aa88ebd88c28a51f0203d0bae Mon Sep 17 00:00:00 2001 From: Gon Kim <87866588+Gonnnnn@users.noreply.github.com> Date: Sat, 19 Nov 2022 14:34:52 +0900 Subject: [PATCH 008/149] =?UTF-8?q?npm=20ci=EB=A5=BC=20npm=20install?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit package-lock.json을 gitignore에 포함시켰기에 npm ci 불가능 --- .github/workflows/fe-dev-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fe-dev-ci.yml b/.github/workflows/fe-dev-ci.yml index b3d3c6b..270e0d3 100644 --- a/.github/workflows/fe-dev-ci.yml +++ b/.github/workflows/fe-dev-ci.yml @@ -30,7 +30,7 @@ jobs: node-version: 18.6.0 - name: Install dependencies - run: npm ci + run: npm install - name: Test run: npm run test From c6b7c75e69238bc3b3233887f7b38688c877fec2 Mon Sep 17 00:00:00 2001 From: Gon Kim <87866588+Gonnnnn@users.noreply.github.com> Date: Sat, 19 Nov 2022 15:22:19 +0900 Subject: [PATCH 009/149] =?UTF-8?q?=ED=99=98=EA=B2=BD=EB=B3=80=EC=88=98=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/fe-dev-ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/fe-dev-ci.yml b/.github/workflows/fe-dev-ci.yml index 270e0d3..809c1ee 100644 --- a/.github/workflows/fe-dev-ci.yml +++ b/.github/workflows/fe-dev-ci.yml @@ -31,6 +31,12 @@ jobs: - name: Install dependencies run: npm install + + - name: Inject Environment Variables + env: + FE_ENV: ${{ secrets.REACT_APP_DOMAIN }} + run: | + echo $FE_ENV > .env - name: Test run: npm run test From 18df8b108b1fc91a6fd4ab83bc7a41ca0e8c0914 Mon Sep 17 00:00:00 2001 From: Gon Kim <87866588+Gonnnnn@users.noreply.github.com> Date: Sat, 19 Nov 2022 15:24:30 +0900 Subject: [PATCH 010/149] =?UTF-8?q?=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/fe-dev-ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/fe-dev-ci.yml b/.github/workflows/fe-dev-ci.yml index 809c1ee..29345d5 100644 --- a/.github/workflows/fe-dev-ci.yml +++ b/.github/workflows/fe-dev-ci.yml @@ -35,8 +35,7 @@ jobs: - name: Inject Environment Variables env: FE_ENV: ${{ secrets.REACT_APP_DOMAIN }} - run: | - echo $FE_ENV > .env + run: echo $FE_ENV > .env - name: Test run: npm run test From 9057fc2c5f8b39f3d16075eb2824d05294bd4ec4 Mon Sep 17 00:00:00 2001 From: Gon Kim <87866588+Gonnnnn@users.noreply.github.com> Date: Sat, 19 Nov 2022 15:30:53 +0900 Subject: [PATCH 011/149] =?UTF-8?q?env=20=ED=8C=8C=EC=9D=BC=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=ED=99=95=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/fe-dev-ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/fe-dev-ci.yml b/.github/workflows/fe-dev-ci.yml index 29345d5..728884d 100644 --- a/.github/workflows/fe-dev-ci.yml +++ b/.github/workflows/fe-dev-ci.yml @@ -36,6 +36,8 @@ jobs: env: FE_ENV: ${{ secrets.REACT_APP_DOMAIN }} run: echo $FE_ENV > .env - + - name: Check + run: ls && cat .env + - name: Test run: npm run test From 8e83a52134a7eae88e4c19576faba3fbefcb5c36 Mon Sep 17 00:00:00 2001 From: Gon Kim <87866588+Gonnnnn@users.noreply.github.com> Date: Sat, 19 Nov 2022 15:34:42 +0900 Subject: [PATCH 012/149] =?UTF-8?q?env=20=ED=8C=8C=EC=9D=BC=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/fe-dev-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/fe-dev-ci.yml b/.github/workflows/fe-dev-ci.yml index 728884d..089c737 100644 --- a/.github/workflows/fe-dev-ci.yml +++ b/.github/workflows/fe-dev-ci.yml @@ -34,10 +34,10 @@ jobs: - name: Inject Environment Variables env: - FE_ENV: ${{ secrets.REACT_APP_DOMAIN }} + FE_ENV: ${{ secrets.FE_ENV }} run: echo $FE_ENV > .env - name: Check - run: ls && cat .env + run: ls -a && cat .env - name: Test run: npm run test From e011741b7401bb21c1b881afde0d7cba3a173f57 Mon Sep 17 00:00:00 2001 From: Gon Kim <87866588+Gonnnnn@users.noreply.github.com> Date: Sat, 19 Nov 2022 16:05:55 +0900 Subject: [PATCH 013/149] =?UTF-8?q?echo=20=EB=82=B4=EC=9A=A9=EC=97=90=20""?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/fe-dev-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fe-dev-ci.yml b/.github/workflows/fe-dev-ci.yml index 089c737..b3d9cd7 100644 --- a/.github/workflows/fe-dev-ci.yml +++ b/.github/workflows/fe-dev-ci.yml @@ -35,7 +35,7 @@ jobs: - name: Inject Environment Variables env: FE_ENV: ${{ secrets.FE_ENV }} - run: echo $FE_ENV > .env + run: echo "$FE_ENV" > .env - name: Check run: ls -a && cat .env From bf0143a96cdf52e50e95e3f05fa8f935e0ab556c Mon Sep 17 00:00:00 2001 From: unho-00 Date: Sat, 19 Nov 2022 16:09:49 +0900 Subject: [PATCH 014/149] =?UTF-8?q?fix:=20[FE]=20OAuth=20=EB=A6=AC?= =?UTF-8?q?=EB=8B=A4=EC=9D=B4=EB=A0=89=ED=8A=B8=20=EC=9D=B4=ED=9B=84=20?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=80=20=EB=A0=8C=EB=8D=94=EB=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 리다이렉트 이후 로그인 페이지 다시 보여지는 이슈 - 로딩중이라는 텍스트를 렌더링 - 이후 로딩 컴포넌트 추가 필요 --- packages/client/src/pages/Signin/index.tsx | 58 +++++++++++++++------- packages/client/src/types/.gitkeep | 0 packages/client/src/types/Signin.ts | 4 ++ 3 files changed, 44 insertions(+), 18 deletions(-) delete mode 100644 packages/client/src/types/.gitkeep create mode 100644 packages/client/src/types/Signin.ts diff --git a/packages/client/src/pages/Signin/index.tsx b/packages/client/src/pages/Signin/index.tsx index 9bf9c47..008a08a 100644 --- a/packages/client/src/pages/Signin/index.tsx +++ b/packages/client/src/pages/Signin/index.tsx @@ -1,6 +1,8 @@ -import axios, { AxiosError } from 'axios'; -import { useCallback, useEffect } from 'react'; +import { useCallback } from 'react'; import { useNavigate, useSearchParams } from 'react-router-dom'; +import axios, { AxiosError } from 'axios'; + +import { chkUser } from 'types/Signin'; import { Container, Logo, NaverOAuth } from './styled'; function Signin() { @@ -10,6 +12,11 @@ function Signin() { const [searchParams] = useSearchParams(); const navigate = useNavigate(); + /** + * 네이버 OAuth 로그인 버튼 클릭 시, 실행되는 함수 + * + * 네이버 로그인을 위한 링크로 이동 + */ const handleClickOAuth = useCallback(() => { if (!naverOAuthURL) return; @@ -17,28 +24,43 @@ function Signin() { }, [naverOAuthURL]); /** - * 메인 페이지 접속 시, 쿼리스트링 여부 판단 + * 네이버 OAuth 리다이렉트 받은 이후 가입 여부 확인 * - * 쿼리 스트링 존재하면 로그인 진행중 + * 서버 응답에 따라 페이지 라우팅 + * + * @params { code, state }: OAuth 리다이렉트 응답 받은 쿼리 */ - useEffect(() => { - const code = searchParams.get('code'); + const chkUser = useCallback( + async ({ code, state }: chkUser) => { const state = searchParams.get('state'); - if (!code || !state) return; - - axios - .get(`${api}/user/naver-oauth?code=${code}&state=${state}`, { - withCredentials: true, - }) - .then((res) => { + try { + await axios.get(`${api}/user/naver-oauth?code=${code}&state=${state}`, { + withCredentials: true, + }); navigate('/home'); - }) - .catch((err: AxiosError) => { - if (err.response && err.response.status === 303) navigate('/signup'); + } catch (err) { + const axiosError = err instanceof AxiosError; + + if (axiosError && err.response?.status === 303) navigate('/signup'); else navigate('/'); - }); - }, [searchParams, navigate, api]); + } + }, + [api, navigate] + ); + + /** + * 메인 페이지 접속 시, 쿼리 존재 여부 판단 + * + * 네이버 OAuth 리다이렉트를 받아 쿼리 존재하면 가입여부 확인 진행 + */ + const code = searchParams.get('code'); + const state = searchParams.get('state'); + + if (code && state) { + chkUser({ code, state }); + return

...loading

; + } return ( diff --git a/packages/client/src/types/.gitkeep b/packages/client/src/types/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/packages/client/src/types/Signin.ts b/packages/client/src/types/Signin.ts new file mode 100644 index 0000000..8f0e3ac --- /dev/null +++ b/packages/client/src/types/Signin.ts @@ -0,0 +1,4 @@ +export interface chkUser { + code: string; + state: string; +} From 312f8135c880f0cc1b262a9ee551775b849a596a Mon Sep 17 00:00:00 2001 From: unho-00 Date: Sat, 19 Nov 2022 16:11:49 +0900 Subject: [PATCH 015/149] =?UTF-8?q?fix:=20[FE]=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85=20=EB=98=90=EB=8A=94=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EC=84=B1=EA=B3=B5=20=EC=9D=B4=ED=9B=84=20=EB=92=A4?= =?UTF-8?q?=EB=A1=9C=EA=B0=80=EA=B8=B0=20=EC=A7=84=ED=96=89=20=EC=8B=9C,?= =?UTF-8?q?=20=EC=9E=90=EB=8F=99=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD=20=EC=9D=B4=EC=8A=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 회원가입 또는 로그인 성공 이후, 뒤로가기 진행 시 이전의 쿼리를 기억하고 있음 - 쿼리 값을 토대로 자동으로 다시 로그인 요청 진행 - 서버는 이전에 사용한 code, state 값이므로 오류 반환 --- packages/client/src/pages/Signin/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/client/src/pages/Signin/index.tsx b/packages/client/src/pages/Signin/index.tsx index 008a08a..aa2a0c5 100644 --- a/packages/client/src/pages/Signin/index.tsx +++ b/packages/client/src/pages/Signin/index.tsx @@ -32,7 +32,7 @@ function Signin() { */ const chkUser = useCallback( async ({ code, state }: chkUser) => { - const state = searchParams.get('state'); + window.history.replaceState(null, '', '/'); try { await axios.get(`${api}/user/naver-oauth?code=${code}&state=${state}`, { From a610cb49af7f5467077e558646c36bc0669d9788 Mon Sep 17 00:00:00 2001 From: Gon Kim <87866588+Gonnnnn@users.noreply.github.com> Date: Sat, 19 Nov 2022 16:15:19 +0900 Subject: [PATCH 016/149] =?UTF-8?q?event=20branch/path=20dev=20=EB=B0=8F?= =?UTF-8?q?=20client=EB=A1=9C=20=EC=88=98=EC=A0=95,=20=ED=99=98=EA=B2=BD?= =?UTF-8?q?=EB=B3=80=EC=88=98=20=EB=93=A4=EC=96=B4=EA=B0=94=EB=8A=94?= =?UTF-8?q?=EC=A7=80=20=EC=B2=B4=ED=81=AC=ED=95=98=EB=8A=94=20=EB=B6=80?= =?UTF-8?q?=EB=B6=84=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/fe-dev-ci.yml | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/.github/workflows/fe-dev-ci.yml b/.github/workflows/fe-dev-ci.yml index b3d9cd7..c3748ee 100644 --- a/.github/workflows/fe-dev-ci.yml +++ b/.github/workflows/fe-dev-ci.yml @@ -2,9 +2,8 @@ name: Frontend dev ci on: push: - branches: [feat/be/front-ci] - # pull_request: - # branches: [dev] + branches: [dev] + paths: './packages/client' jobs: ci: @@ -13,13 +12,6 @@ jobs: run: working-directory: './packages/client' - # job - strategy: - # matrix 아래에는 matrix.xxx와 같은 방법으로 참조 가능한 변수를 선언 - # job은 각각의 변수들을 가지고 combinations를 만들어 실행시킨다. - matrix: - node-version: [18.x] - steps: - name: checkout to the branch uses: actions/checkout@v3 @@ -36,8 +28,6 @@ jobs: env: FE_ENV: ${{ secrets.FE_ENV }} run: echo "$FE_ENV" > .env - - name: Check - run: ls -a && cat .env - name: Test run: npm run test From 7082a42ece6e41a369eef1a882bc568e9995ca84 Mon Sep 17 00:00:00 2001 From: Gon Kim Date: Sat, 19 Nov 2022 17:02:04 +0900 Subject: [PATCH 017/149] =?UTF-8?q?refactor:=20[BE]=20ci=20event=20pr?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/fe-dev-ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/fe-dev-ci.yml b/.github/workflows/fe-dev-ci.yml index c3748ee..5a3294f 100644 --- a/.github/workflows/fe-dev-ci.yml +++ b/.github/workflows/fe-dev-ci.yml @@ -1,7 +1,7 @@ name: Frontend dev ci on: - push: + pull_request: branches: [dev] paths: './packages/client' @@ -23,11 +23,11 @@ jobs: - name: Install dependencies run: npm install - + - name: Inject Environment Variables env: FE_ENV: ${{ secrets.FE_ENV }} run: echo "$FE_ENV" > .env - + - name: Test run: npm run test From 3cafecfc284c4122fba31ec213d4b6d95624458c Mon Sep 17 00:00:00 2001 From: Gon Kim Date: Sat, 19 Nov 2022 17:02:27 +0900 Subject: [PATCH 018/149] =?UTF-8?q?feat:=20[BE]=20fe=20dev=20cd=20?= =?UTF-8?q?=EC=9E=84=EC=8B=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=9A=A9=20?= =?UTF-8?q?=EC=BB=A4=EB=B0=8B=20-=20=ED=98=84=EC=9E=AC=20=EB=B8=8C?= =?UTF-8?q?=EB=9E=9C=EC=B9=98=20=ED=91=B8=EC=8B=9C=EC=97=90=20=EB=B0=9C?= =?UTF-8?q?=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/fe-dev-cd.yml | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/fe-dev-cd.yml diff --git a/.github/workflows/fe-dev-cd.yml b/.github/workflows/fe-dev-cd.yml new file mode 100644 index 0000000..6088a8a --- /dev/null +++ b/.github/workflows/fe-dev-cd.yml @@ -0,0 +1,43 @@ +name: Frontend dev cd + +on: + push: + branches: [feat/be/front-cd] + paths: './packages/client' + +jobs: + cd: + runs-on: ubuntu-latest + defaults: + run: + working-directory: './packages/client' + + steps: + - name: checkout to the branch + uses: actions/checkout@v3 + + - name: node set-up + uses: actions/setup-node@v3 + with: + node-version: 18.6.0 + + - name: Install dependencies + run: npm install + + - name: Inject Environment Variables + env: + FE_ENV: ${{ secrets.FE_ENV }} + run: echo "$FE_ENV" > .env + + - name: Build + run: npm run build + + - name: Deploy to Remote Server + uses: appleboy/scp-action@master + with: + host: ${{ secrets.REMOTE_SSH_HOST }} + username: ${{ secrets.REMOTE_SSH_USERNAME }} + password: ${{ secrets.REMOTE_SSH_PASSWORD }} + port: ${{ secrets.REMOTE_SSH_PORT }} + source: './build/*' + target: '~/client/build' From 5912706092c393b1a94e209da2103307491f7f0f Mon Sep 17 00:00:00 2001 From: Gon Kim Date: Sat, 19 Nov 2022 17:05:44 +0900 Subject: [PATCH 019/149] test --- packages/client/test.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 packages/client/test.txt diff --git a/packages/client/test.txt b/packages/client/test.txt new file mode 100644 index 0000000..2c5f3af --- /dev/null +++ b/packages/client/test.txt @@ -0,0 +1 @@ +ㅋㅋ \ No newline at end of file From a1343f87140052476ff688a367292f4cef7b9ad3 Mon Sep 17 00:00:00 2001 From: qmdl980 Date: Sun, 20 Nov 2022 22:10:25 +0900 Subject: [PATCH 020/149] =?UTF-8?q?feat:=20[FE]=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/src/pages/Signin/index.spec.tsx | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/client/src/pages/Signin/index.spec.tsx b/packages/client/src/pages/Signin/index.spec.tsx index 8f171a7..89f88d6 100644 --- a/packages/client/src/pages/Signin/index.spec.tsx +++ b/packages/client/src/pages/Signin/index.spec.tsx @@ -1,14 +1,21 @@ import { render, screen } from '@testing-library/react'; -import Signin from './index'; +import { MemoryRouter } from 'react-router-dom'; +import Router from '@/Router'; import Layout from '@/Layout'; +const setup = () => { + render( + + + + + + ); +}; + describe('Signin', () => { it('Has Elements', () => { - render( - - - - ); + setup(); screen.getByAltText('로고'); screen.getByAltText('네이버 로그인'); From a21e9e0e1fc89b2408904beccdc01f277bac0157 Mon Sep 17 00:00:00 2001 From: Gon Kim Date: Sun, 20 Nov 2022 22:52:30 +0900 Subject: [PATCH 021/149] =?UTF-8?q?fix:=20[BE]=20branch=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EB=94=B0=EC=98=B4=ED=91=9C=EB=A1=9C=20=EA=B0=90?= =?UTF-8?q?=EC=8B=B8=20parse=20error=20=EB=B0=A9=EC=A7=80.=20path=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/fe-dev-cd.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/fe-dev-cd.yml b/.github/workflows/fe-dev-cd.yml index 6088a8a..1514ac5 100644 --- a/.github/workflows/fe-dev-cd.yml +++ b/.github/workflows/fe-dev-cd.yml @@ -2,8 +2,8 @@ name: Frontend dev cd on: push: - branches: [feat/be/front-cd] - paths: './packages/client' + branches: ['feat/be/front-cd'] + paths: 'packages/client' jobs: cd: From d930c5d1192f22b1aa27c2e4c05c3f2b4bae7866 Mon Sep 17 00:00:00 2001 From: Gon Kim Date: Sun, 20 Nov 2022 22:55:30 +0900 Subject: [PATCH 022/149] =?UTF-8?q?fix:=20[BE]=20path=EC=97=90=20wildcard?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/fe-dev-cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fe-dev-cd.yml b/.github/workflows/fe-dev-cd.yml index 1514ac5..c3dcc3e 100644 --- a/.github/workflows/fe-dev-cd.yml +++ b/.github/workflows/fe-dev-cd.yml @@ -3,7 +3,7 @@ name: Frontend dev cd on: push: branches: ['feat/be/front-cd'] - paths: 'packages/client' + paths: 'packages/client/**' jobs: cd: From 22842996213a43e50cb853b91abb86c3d83adf89 Mon Sep 17 00:00:00 2001 From: Gon Kim Date: Sun, 20 Nov 2022 22:57:17 +0900 Subject: [PATCH 023/149] =?UTF-8?q?fix:=20[BE]=20=EB=B3=B8=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=88=98=EC=A0=95=EB=8F=84=20event=EB=A1=9C=20?= =?UTF-8?q?=EC=9E=A1=ED=9E=88=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/fe-dev-cd.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/fe-dev-cd.yml b/.github/workflows/fe-dev-cd.yml index c3dcc3e..11192d0 100644 --- a/.github/workflows/fe-dev-cd.yml +++ b/.github/workflows/fe-dev-cd.yml @@ -3,7 +3,9 @@ name: Frontend dev cd on: push: branches: ['feat/be/front-cd'] - paths: 'packages/client/**' + paths: + - 'packages/client/**' + - '.github/workflows/fe-dev-cd.yml' jobs: cd: From 2a90e1cc385fdd4c8d50e34ba5cade61aa7d1027 Mon Sep 17 00:00:00 2001 From: qmdl980 Date: Sun, 20 Nov 2022 23:19:25 +0900 Subject: [PATCH 024/149] =?UTF-8?q?refactor:=20[FE]=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=EB=A6=AC=EB=B7=B0=20=ED=94=BC=EB=93=9C=EB=B0=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 회원가입 type 0과1로 분리 - if문 중첩 함수로 분리 - 동일 로직 함수로 분리 - 테스트 코드 수정 --- .../client/src/pages/Signup/index.spec.tsx | 8 +- packages/client/src/pages/Signup/index.tsx | 103 ++++++++---------- packages/client/src/types/Signup.ts | 2 +- 3 files changed, 54 insertions(+), 59 deletions(-) diff --git a/packages/client/src/pages/Signup/index.spec.tsx b/packages/client/src/pages/Signup/index.spec.tsx index 62d11e9..8269e8a 100644 --- a/packages/client/src/pages/Signup/index.spec.tsx +++ b/packages/client/src/pages/Signup/index.spec.tsx @@ -7,14 +7,16 @@ import { MemoryRouter } from 'react-router-dom'; import Router from '@/Router'; import Layout from '@/Layout'; +const api = process.env.REACT_APP_API_SERVER_BASE_URL; + const server = setupServer( rest.post( - 'http://localhost:8080/api/v1/user/signup', + `${api}/user/signup`, (req: RestRequest, res, next) => { const { userType, nickname, corporate } = req.body; - if (userType === 'owner' && corporate && nickname) { + if (userType === 1 && corporate && nickname) { return res(next.status(201)); - } else if (userType === 'customer' && nickname) { + } else if (userType === 0 && nickname) { return res(next.status(201)); } else { return res(next.status(400)); diff --git a/packages/client/src/pages/Signup/index.tsx b/packages/client/src/pages/Signup/index.tsx index b6c1c6e..59a9f3c 100644 --- a/packages/client/src/pages/Signup/index.tsx +++ b/packages/client/src/pages/Signup/index.tsx @@ -11,70 +11,46 @@ import { Input, CustomButton, } from './styled'; +import { SignupRequestBody } from 'types/Signup'; function Signup() { const api = process.env.REACT_APP_API_SERVER_BASE_URL; - const [signupType, setSignupType] = useState('customer'); + //userType -> 고객인 경우 0, 업주인 경우 1 + const [userType, setuserType] = useState(0); const [nickname, setNickname] = useState(''); const [corporate, setCorporate] = useState(''); const navigate = useNavigate(); const handleClickCustomer = () => { - setSignupType('customer'); + setuserType(0); }; const handleClickOwner = () => { - setSignupType('owner'); + setuserType(1); }; - const handleSubmit = () => { - if (isValidateNickname()) { - if (signupType === 'owner') { - if (isValidateCorporate()) { - axios - .post( - `${api}/user/signup`, - { - userType: 1, - nickname, - corporate, - }, - { withCredentials: true } - ) - .then((res) => { - if (res.status === 201) { - navigate('/home'); - } - }) - .catch((err) => { - console.log(err); - }); - } else { - alert('사업자 등록 번호 입력이 잘못됐습니다.'); - } - } else { - axios - .post( - `${process.env.REACT_APP_API_SERVER_BASE_URL}/user/signup`, - { - userType: 0, - nickname, - }, - { - withCredentials: true, - } - ) - .then((res) => { - if (res.status === 201) { - navigate('/home'); - } - }) - .catch((err) => { - console.log(err); - }); + const handleSubmit = async () => { + if(!userType){ + if(isValidateCustomerForm()){ + fetchSignup({userType, nickname}) } - } else { - alert('닉네임 입력이 잘못됐습니다.'); + }else{ + if(isValidateOwnerForm()){ + fetchSignup({userType, nickname, corporate}) + } + } + }; + + const fetchSignup = async (data: SignupRequestBody) => { + try { + const res = await axios.post(`${api}/user/signup`, data, { + withCredentials: true, + }); + if (res.status === 201) { + navigate('/home'); + } + } catch (err) { + console.log(err); } }; @@ -86,25 +62,42 @@ function Signup() { setCorporate(e.target.value.replace(/[^0-9-]/g, '')); }; + const isValidateCustomerForm = () => { + if(isValidateNickname()) return true; + return false; + } + + const isValidateOwnerForm = () => { + if(isValidateNickname()){ + if(isValidateCorporate()) return true; + } + return false; + } + + const isValidateNickname = () => { - return nickname.length > 2; + if(nickname.length > 2) return true; + alert('닉네임 입력이 잘못됐습니다'); + return false; }; const isValidateCorporate = () => { - return corporate.length >= 10; + if(corporate.length >= 10) return true; + alert('사업자 등록 번호 입력이 잘못됐습니다') + return false; }; return ( 고객 업주 @@ -120,7 +113,7 @@ function Signup() { value={nickname} /> - {signupType === 'owner' ? ( + {userType ? ( 사업자 등록 번호 Date: Sun, 20 Nov 2022 23:19:33 +0900 Subject: [PATCH 025/149] =?UTF-8?q?fix:=20[BE]=20scp=20action=20source?= =?UTF-8?q?=EB=A5=BC=20build=20=EB=94=94=EB=A0=89=ED=86=A0=EB=A6=AC=20?= =?UTF-8?q?=EC=A0=84=EC=B2=B4=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/fe-dev-cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fe-dev-cd.yml b/.github/workflows/fe-dev-cd.yml index 11192d0..aad4929 100644 --- a/.github/workflows/fe-dev-cd.yml +++ b/.github/workflows/fe-dev-cd.yml @@ -41,5 +41,5 @@ jobs: username: ${{ secrets.REMOTE_SSH_USERNAME }} password: ${{ secrets.REMOTE_SSH_PASSWORD }} port: ${{ secrets.REMOTE_SSH_PORT }} - source: './build/*' + source: './build' target: '~/client/build' From e0d25101ab53932f8f44f3af7b878518ddc283ec Mon Sep 17 00:00:00 2001 From: qmdl980 Date: Sun, 20 Nov 2022 23:21:54 +0900 Subject: [PATCH 026/149] =?UTF-8?q?style:=20prettier=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/client/src/pages/Signup/index.tsx | 29 +++++++++++----------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/packages/client/src/pages/Signup/index.tsx b/packages/client/src/pages/Signup/index.tsx index 59a9f3c..d8ac0bd 100644 --- a/packages/client/src/pages/Signup/index.tsx +++ b/packages/client/src/pages/Signup/index.tsx @@ -30,13 +30,13 @@ function Signup() { }; const handleSubmit = async () => { - if(!userType){ - if(isValidateCustomerForm()){ - fetchSignup({userType, nickname}) + if (!userType) { + if (isValidateCustomerForm()) { + fetchSignup({ userType, nickname }); } - }else{ - if(isValidateOwnerForm()){ - fetchSignup({userType, nickname, corporate}) + } else { + if (isValidateOwnerForm()) { + fetchSignup({ userType, nickname, corporate }); } } }; @@ -63,27 +63,26 @@ function Signup() { }; const isValidateCustomerForm = () => { - if(isValidateNickname()) return true; + if (isValidateNickname()) return true; return false; - } + }; const isValidateOwnerForm = () => { - if(isValidateNickname()){ - if(isValidateCorporate()) return true; + if (isValidateNickname()) { + if (isValidateCorporate()) return true; } return false; - } - + }; const isValidateNickname = () => { - if(nickname.length > 2) return true; + if (nickname.length > 2) return true; alert('닉네임 입력이 잘못됐습니다'); return false; }; const isValidateCorporate = () => { - if(corporate.length >= 10) return true; - alert('사업자 등록 번호 입력이 잘못됐습니다') + if (corporate.length >= 10) return true; + alert('사업자 등록 번호 입력이 잘못됐습니다'); return false; }; From 8105a91ffc296d303546301340659cfc6ceae216 Mon Sep 17 00:00:00 2001 From: Gon Kim Date: Sun, 20 Nov 2022 23:23:11 +0900 Subject: [PATCH 027/149] =?UTF-8?q?fix:=20[BE]=20source=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/fe-dev-cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fe-dev-cd.yml b/.github/workflows/fe-dev-cd.yml index aad4929..35b486c 100644 --- a/.github/workflows/fe-dev-cd.yml +++ b/.github/workflows/fe-dev-cd.yml @@ -41,5 +41,5 @@ jobs: username: ${{ secrets.REMOTE_SSH_USERNAME }} password: ${{ secrets.REMOTE_SSH_PASSWORD }} port: ${{ secrets.REMOTE_SSH_PORT }} - source: './build' + source: 'build/*' target: '~/client/build' From 3ce81398a8da3315eb72c271595024f266d089b0 Mon Sep 17 00:00:00 2001 From: Gon Kim <87866588+Gonnnnn@users.noreply.github.com> Date: Mon, 21 Nov 2022 01:32:28 +0900 Subject: [PATCH 028/149] =?UTF-8?q?source=EB=A5=BC=20repo=20root=EC=97=90?= =?UTF-8?q?=EC=84=9C=EB=B6=80=ED=84=B0=20=EC=8B=9C=EC=9E=91=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95,=20=EA=B7=B8=EC=97=90?= =?UTF-8?q?=20=EB=A7=9E=EA=B2=8C=20strip=5Fcomponents=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/fe-dev-cd.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/fe-dev-cd.yml b/.github/workflows/fe-dev-cd.yml index 35b486c..0f98c69 100644 --- a/.github/workflows/fe-dev-cd.yml +++ b/.github/workflows/fe-dev-cd.yml @@ -41,5 +41,6 @@ jobs: username: ${{ secrets.REMOTE_SSH_USERNAME }} password: ${{ secrets.REMOTE_SSH_PASSWORD }} port: ${{ secrets.REMOTE_SSH_PORT }} - source: 'build/*' + source: 'packages/client/build/*' target: '~/client/build' + strip_components: 3 From a9c1dfe45d9d1bf0e372fc52a8d128d4539fde36 Mon Sep 17 00:00:00 2001 From: Gon Kim <87866588+Gonnnnn@users.noreply.github.com> Date: Mon, 21 Nov 2022 01:37:19 +0900 Subject: [PATCH 029/149] =?UTF-8?q?fix:=20[BE]=20event=20branch=EB=A5=BC?= =?UTF-8?q?=20dev=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/fe-dev-cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fe-dev-cd.yml b/.github/workflows/fe-dev-cd.yml index 0f98c69..5848850 100644 --- a/.github/workflows/fe-dev-cd.yml +++ b/.github/workflows/fe-dev-cd.yml @@ -2,7 +2,7 @@ name: Frontend dev cd on: push: - branches: ['feat/be/front-cd'] + branches: ['dev'] paths: - 'packages/client/**' - '.github/workflows/fe-dev-cd.yml' From c6e0bdb9956af5d222fbd2cdee7118852368ec8f Mon Sep 17 00:00:00 2001 From: qmdl980 Date: Mon, 21 Nov 2022 13:13:41 +0900 Subject: [PATCH 030/149] =?UTF-8?q?feat:=20[FE]=20recoil=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 예시 작성 --- packages/client/package.json | 1 + packages/client/src/App.tsx | 13 ++++++++----- packages/client/src/types/Cart.ts | 6 ++++++ packages/client/src/utils/store.ts | 7 +++++++ 4 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 packages/client/src/types/Cart.ts create mode 100644 packages/client/src/utils/store.ts diff --git a/packages/client/package.json b/packages/client/package.json index 64315eb..ef714e0 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -17,6 +17,7 @@ "react-dom": "^18.2.0", "react-router-dom": "^6.4.3", "react-scripts": "5.0.1", + "recoil": "^0.7.6", "typescript": "^4.8.4", "web-vitals": "^2.1.4" }, diff --git a/packages/client/src/App.tsx b/packages/client/src/App.tsx index c0fc646..176b75c 100644 --- a/packages/client/src/App.tsx +++ b/packages/client/src/App.tsx @@ -1,15 +1,18 @@ import { BrowserRouter } from 'react-router-dom'; +import { RecoilRoot } from 'recoil'; import Router from '@/Router'; import Layout from '@/Layout'; function App() { return (
- - - - - + + + + + + +
); } diff --git a/packages/client/src/types/Cart.ts b/packages/client/src/types/Cart.ts new file mode 100644 index 0000000..9c8cfe6 --- /dev/null +++ b/packages/client/src/types/Cart.ts @@ -0,0 +1,6 @@ +export interface CartMenu { + id: number; + name: string; + price: number; + options: number[]; +} diff --git a/packages/client/src/utils/store.ts b/packages/client/src/utils/store.ts new file mode 100644 index 0000000..529d3c5 --- /dev/null +++ b/packages/client/src/utils/store.ts @@ -0,0 +1,7 @@ +import { atom } from 'recoil'; +import { CartMenu } from '@/types/Cart'; + +export const cartState = atom({ + key: 'cartState', + default: [], +}); From 23524e9389b4ab89ddf4f16fb31375df970122e6 Mon Sep 17 00:00:00 2001 From: unho-00 Date: Mon, 21 Nov 2022 13:29:38 +0900 Subject: [PATCH 031/149] =?UTF-8?q?feat:=20[FE]=20=EB=A1=9C=EA=B3=A0=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=EC=9C=BC=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20?= =?UTF-8?q?=EC=8A=A4=ED=83=80=EC=9D=BC=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/client/src/pages/Signin/styled.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/client/src/pages/Signin/styled.ts b/packages/client/src/pages/Signin/styled.ts index 0ef7c1c..1fc2a1e 100644 --- a/packages/client/src/pages/Signin/styled.ts +++ b/packages/client/src/pages/Signin/styled.ts @@ -15,7 +15,6 @@ export const Container = styled.div` export const Logo = styled.img` width: 60%; - border-radius: ${(props) => props.theme.border.radius}; `; export const NaverOAuth = styled.img` From 5f447ee704f887c3d2b034798d0ad4dad2c909be Mon Sep 17 00:00:00 2001 From: unho-00 Date: Mon, 21 Nov 2022 13:34:24 +0900 Subject: [PATCH 032/149] =?UTF-8?q?feat:=20[FE]=20msw=20mock=20=ED=8F=B4?= =?UTF-8?q?=EB=8D=94=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 핸들러 구분 --- packages/client/src/mocks/handlers/auth.ts | 20 ++++++++++++++++++++ packages/client/src/mocks/handlers/index.ts | 3 +++ packages/client/src/mocks/server.ts | 4 ++++ 3 files changed, 27 insertions(+) create mode 100644 packages/client/src/mocks/handlers/auth.ts create mode 100644 packages/client/src/mocks/handlers/index.ts create mode 100644 packages/client/src/mocks/server.ts diff --git a/packages/client/src/mocks/handlers/auth.ts b/packages/client/src/mocks/handlers/auth.ts new file mode 100644 index 0000000..c4e25ff --- /dev/null +++ b/packages/client/src/mocks/handlers/auth.ts @@ -0,0 +1,20 @@ +import { rest } from 'msw'; + +const naverOAuthURL = process.env.REACT_APP_NAVER_OAUTH_URL!.split('?')[0]; +const api = process.env.REACT_APP_API_SERVER_BASE_URL; + +export const authHandlers = [ + // 네이버 로그인 OAuth 요청 + rest.get(naverOAuthURL, (req, res, ctx) => { + return res(ctx.status(200)); + }), + // OAuth code, state 서버 전송 및 응답 + rest.get(`${api}/user/naver-oauth`, (req, res, ctx) => { + const { name, email } = req.cookies; + + if (name && email) { + return res(ctx.status(200)); + } + return res(ctx.status(303)); + }), +]; diff --git a/packages/client/src/mocks/handlers/index.ts b/packages/client/src/mocks/handlers/index.ts new file mode 100644 index 0000000..d271994 --- /dev/null +++ b/packages/client/src/mocks/handlers/index.ts @@ -0,0 +1,3 @@ +import { authHandlers } from './auth'; + +export const handlers = [...authHandlers]; diff --git a/packages/client/src/mocks/server.ts b/packages/client/src/mocks/server.ts new file mode 100644 index 0000000..aec3f55 --- /dev/null +++ b/packages/client/src/mocks/server.ts @@ -0,0 +1,4 @@ +import { setupServer } from 'msw/node'; +import { handlers } from './handlers/index'; + +export const server = setupServer(...handlers); From 0087571cc502367de226e6936a2643380b00e33f Mon Sep 17 00:00:00 2001 From: unho-00 Date: Mon, 21 Nov 2022 13:35:22 +0900 Subject: [PATCH 033/149] =?UTF-8?q?feat:=20[FE]=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Signin/__snapshots__/index.spec.tsx.snap | 34 +++++++ .../client/src/pages/Signin/index.spec.tsx | 98 +++++++++++++++++-- packages/client/src/pages/Signin/index.tsx | 16 +-- 3 files changed, 132 insertions(+), 16 deletions(-) create mode 100644 packages/client/src/pages/Signin/__snapshots__/index.spec.tsx.snap diff --git a/packages/client/src/pages/Signin/__snapshots__/index.spec.tsx.snap b/packages/client/src/pages/Signin/__snapshots__/index.spec.tsx.snap new file mode 100644 index 0000000..479cb92 --- /dev/null +++ b/packages/client/src/pages/Signin/__snapshots__/index.spec.tsx.snap @@ -0,0 +1,34 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`로그인 페이지 스냡샷 1`] = ` + +
+
+ 로고 +
+

+ 오직 당신만을 위한 카페 주문 +

+

+ 부따 (부스트 다방, Buddha) +

+
+ 네이버 로그인 +
+
+
+`; diff --git a/packages/client/src/pages/Signin/index.spec.tsx b/packages/client/src/pages/Signin/index.spec.tsx index 8f171a7..692a655 100644 --- a/packages/client/src/pages/Signin/index.spec.tsx +++ b/packages/client/src/pages/Signin/index.spec.tsx @@ -1,19 +1,97 @@ -import { render, screen } from '@testing-library/react'; -import Signin from './index'; +import { fireEvent, render, screen, waitFor } from '@testing-library/react'; import Layout from '@/Layout'; +import { server } from '@/mocks/server'; +import { MemoryRouter } from 'react-router-dom'; +import Router from '@/Router'; +import { PLACEHOLDER } from '@/constants'; -describe('Signin', () => { - it('Has Elements', () => { - render( - - - - ); +beforeAll(() => server.listen()); +beforeEach(() => server.resetHandlers()); +afterAll(() => server.close()); + +const setup = ({ url }: { url: string }) => { + const { asFragment } = render( + + + + + + ); + + return { asFragment }; +}; + +describe('로그인 페이지', () => { + it('로고, 버튼 요소 존재 여부', () => { + setup({ url: '/' }); screen.getByAltText('로고'); screen.getByAltText('네이버 로그인'); const description = screen.getAllByTitle('소개'); - expect(description).toHaveLength(1); + expect(description.length).toBeGreaterThanOrEqual(1); + }); + + it('네이버 OAuth 로그인 버튼 클릭', () => { + setup({ url: '/' }); + + /** + * Stack overflow + * https://stackoverflow.com/questions/54090231/how-to-fix-error-not-implemented-navigation-except-hash-changes + * + * https://github.com/jsdom/jsdom/issues/2112 + * https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty + */ + Object.defineProperty(window, 'location', { + value: { assign: jest.fn() }, + }); + const btnSignin = screen.getByAltText('네이버 로그인'); + + fireEvent.click(btnSignin); + window.location.search = '?code=asdwfwqd134caw&state=1234'; + + expect(window.location.search).toEqual(expect.stringContaining('?code=')); + expect(window.location.search).toEqual(expect.stringContaining('&state=')); + }); + + it('네이버 OAuth 로그인 리다이렉트', () => { + setup({ url: '/?code=qwer1234&state=1234' }); + + const logo = screen.queryByAltText('로고'); + const btnSignin = screen.queryByAltText('네이버 로그인'); + const description = screen.queryAllByTitle('소개'); + + expect(logo).toBeNull(); + expect(btnSignin).toBeNull(); + expect(description).toHaveLength(0); + }); + + it('미가입 유저 => 회원가입 페이지 이동', async () => { + setup({ url: '/?code=qwer1234&state=1234' }); + + await waitFor(() => { + screen.getByText('고객'); + screen.getByText('업주'); + screen.getByPlaceholderText(PLACEHOLDER.nickname); + screen.getByText('회원가입'); + }); + }); + + it('가입 유저 => 고객 주문 내역 페이지 이동', async () => { + setup({ url: '/?code=qwer1234&state=1234' }); + + Object.defineProperty(window.document, 'cookie', { + value: 'name=이름;email=test@test.com', + }); + + await waitFor(() => { + screen.getByText(/주문 내역/i); + }); + }); + + it('스냡샷', () => { + const { asFragment } = setup({ url: '/' }); + + expect(asFragment()).toMatchSnapshot(); }); }); diff --git a/packages/client/src/pages/Signin/index.tsx b/packages/client/src/pages/Signin/index.tsx index 9bf9c47..3381f71 100644 --- a/packages/client/src/pages/Signin/index.tsx +++ b/packages/client/src/pages/Signin/index.tsx @@ -1,5 +1,5 @@ import axios, { AxiosError } from 'axios'; -import { useCallback, useEffect } from 'react'; +import { useCallback } from 'react'; import { useNavigate, useSearchParams } from 'react-router-dom'; import { Container, Logo, NaverOAuth } from './styled'; @@ -21,12 +21,15 @@ function Signin() { * * 쿼리 스트링 존재하면 로그인 진행중 */ - useEffect(() => { - const code = searchParams.get('code'); - const state = searchParams.get('state'); + // useEffect(() => { - if (!code || !state) return; + // if (!code || !state) return; + // }, [searchParams, navigate, api]); + const code = searchParams.get('code'); + const state = searchParams.get('state'); + + if (code && state) { axios .get(`${api}/user/naver-oauth?code=${code}&state=${state}`, { withCredentials: true, @@ -38,7 +41,8 @@ function Signin() { if (err.response && err.response.status === 303) navigate('/signup'); else navigate('/'); }); - }, [searchParams, navigate, api]); + return

loading...

; + } return ( From e1b13d1d8d344bcc5500fe41bde8a4cf429f80da Mon Sep 17 00:00:00 2001 From: Gon Kim Date: Mon, 21 Nov 2022 13:35:52 +0900 Subject: [PATCH 034/149] =?UTF-8?q?refactor:=20[BE]=20user=20=EA=B0=80?= =?UTF-8?q?=EC=9E=85/=ED=83=88=ED=87=B4=20=EB=B0=8F=20=EA=B6=8C=ED=95=9C?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20=EA=B4=80=EB=A0=A8=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=20=EC=A0=84=EB=B6=80=20auth=20=EB=AA=A8=EB=93=88=20=EC=BB=A8?= =?UTF-8?q?=ED=8A=B8=EB=A1=A4=EB=9F=AC=EC=97=90=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/server/src/auth/auth.controller.ts | 58 +++++++++++++++---- packages/server/src/auth/auth.module.ts | 3 +- .../{user => auth}/dto/naver-singIn.dto.ts | 0 .../src/{user => auth}/dto/signup.dto.ts | 2 +- packages/server/src/user/user.controller.ts | 54 +---------------- packages/server/src/user/user.service.ts | 4 +- 6 files changed, 53 insertions(+), 68 deletions(-) rename packages/server/src/{user => auth}/dto/naver-singIn.dto.ts (100%) rename packages/server/src/{user => auth}/dto/signup.dto.ts (66%) diff --git a/packages/server/src/auth/auth.controller.ts b/packages/server/src/auth/auth.controller.ts index c1c458c..7b0f1b9 100644 --- a/packages/server/src/auth/auth.controller.ts +++ b/packages/server/src/auth/auth.controller.ts @@ -3,23 +3,59 @@ import { Get, Post, Body, - Patch, - Param, Delete, + HttpCode, + Query, Req, } from '@nestjs/common'; +import { SignUpDto } from '../auth/dto/signup.dto'; +import { NaverSignInDto } from '../auth/dto/naver-singIn.dto'; + import { Request } from 'express'; import { AuthService } from './auth.service'; +import { UserService } from 'src/user/user.service'; -@Controller('api/v1/auth') +@Controller() export class AuthController { - constructor(private readonly authService: AuthService) {} + constructor( + private readonly authService: AuthService, + private readonly userService: UserService + ) {} + + // 네이버 로그인 + @Get('/naver-oauth') + async naverSignIn( + @Req() req: Request, + @Query() naverSignInDto: NaverSignInDto + ) { + return await this.userService.naverSignIn(req, naverSignInDto); + } + + // 회원가입 + @Post('/signup') + @HttpCode(201) + async signUp(@Req() req: Request, @Body() signUpDto: SignUpDto) { + return await this.userService.signUp(req, signUpDto); + } + + // 로그아웃 + @Post('/signout') + signOut() { + const jwt = 'jwt'; + return this.userService.signOut(jwt); + } + + // 회원 탈퇴 + @Delete() + remove() { + const jwt = 'jwt'; + return this.userService.remove(jwt); + } - // @Get('/naver-oauth') - // async naverOAuthSignIn(@Req() req: Request) { - // const code = req.query.code; - // const state = req.query.state; - // const result = await this.authService.naverOAuthSignIn(req, code, state); - // return result; - // } + // 유저 권한 확인 + @Get() + async checkUser() { + const jwt = 'jwt'; + return jwt; + } } diff --git a/packages/server/src/auth/auth.module.ts b/packages/server/src/auth/auth.module.ts index 7396cb9..9a32c24 100644 --- a/packages/server/src/auth/auth.module.ts +++ b/packages/server/src/auth/auth.module.ts @@ -2,9 +2,10 @@ import { Module } from '@nestjs/common'; import { HttpModule } from '@nestjs/axios'; import { AuthService } from './auth.service'; import { AuthController } from './auth.controller'; +import { UserModule } from 'src/user/user.module'; @Module({ - imports: [HttpModule], + imports: [HttpModule, UserModule], controllers: [AuthController], providers: [AuthService], exports: [AuthService], diff --git a/packages/server/src/user/dto/naver-singIn.dto.ts b/packages/server/src/auth/dto/naver-singIn.dto.ts similarity index 100% rename from packages/server/src/user/dto/naver-singIn.dto.ts rename to packages/server/src/auth/dto/naver-singIn.dto.ts diff --git a/packages/server/src/user/dto/signup.dto.ts b/packages/server/src/auth/dto/signup.dto.ts similarity index 66% rename from packages/server/src/user/dto/signup.dto.ts rename to packages/server/src/auth/dto/signup.dto.ts index 9f50c3e..6352585 100644 --- a/packages/server/src/user/dto/signup.dto.ts +++ b/packages/server/src/auth/dto/signup.dto.ts @@ -1,4 +1,4 @@ -import { USER_TYPE } from '../enum/userType.enum'; +import { USER_TYPE } from '../../user/enum/userType.enum'; export class SignUpDto { readonly userType: USER_TYPE; diff --git a/packages/server/src/user/user.controller.ts b/packages/server/src/user/user.controller.ts index 5c43d0e..6e74c83 100644 --- a/packages/server/src/user/user.controller.ts +++ b/packages/server/src/user/user.controller.ts @@ -1,65 +1,13 @@ -import { - Controller, - Get, - Post, - Body, - Patch, - Param, - Delete, - HttpCode, - Query, - Req, -} from '@nestjs/common'; +import { Controller, Body, Patch } from '@nestjs/common'; import { UserService } from './user.service'; -import { SignUpDto } from './dto/signup.dto'; import { UpdateUserDto } from './dto/update-user.dto'; -import { NaverSignInDto } from './dto/naver-singIn.dto'; -import { Request } from 'express'; - @Controller() export class UserController { constructor(private readonly userService: UserService) {} - // 네이버 로그인 - @Get('/naver-oauth') - async naverSignIn( - @Req() req: Request, - @Query() naverSignInDto: NaverSignInDto - ) { - return await this.userService.naverSignIn(req, naverSignInDto); - } - - // 회원가입 - @Post('/signup') - @HttpCode(201) - async signUp(@Req() req: Request, @Body() signUpDto: SignUpDto) { - return await this.userService.signUp(req, signUpDto); - } - - // 로그아웃 - @Post('/signout') - signOut() { - const jwt = 'jwt'; - return this.userService.signOut(jwt); - } - // 회원정보(닉네임) 수정 @Patch() update(@Body() updateUserDto: UpdateUserDto) { return this.userService.update(updateUserDto); } - - // 회원 탈퇴 - @Delete() - remove() { - const jwt = 'jwt'; - return this.userService.remove(jwt); - } - - // 유저 권한 확인 - @Get() - async checkUser() { - const jwt = 'jwt'; - return jwt; - } } diff --git a/packages/server/src/user/user.service.ts b/packages/server/src/user/user.service.ts index 4931bff..de00b98 100644 --- a/packages/server/src/user/user.service.ts +++ b/packages/server/src/user/user.service.ts @@ -1,12 +1,12 @@ import { HttpException, HttpStatus, Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { FindOneOptions, Repository } from 'typeorm'; -import { SignUpDto } from './dto/signup.dto'; +import { SignUpDto } from '../auth/dto/signup.dto'; import { UpdateUserDto } from './dto/update-user.dto'; import { User } from './entities/user.entity'; import { Request } from 'express'; import { AuthService } from 'src/auth/auth.service'; -import { NaverSignInDto } from './dto/naver-singIn.dto'; +import { NaverSignInDto } from '../auth/dto/naver-singIn.dto'; import { USER_TYPE } from './enum/userType.enum'; @Injectable() From 5775119847727f5f7ee6cefe4c6c9e247c3e9f86 Mon Sep 17 00:00:00 2001 From: qmdl980 Date: Mon, 21 Nov 2022 13:41:52 +0900 Subject: [PATCH 035/149] =?UTF-8?q?feat:=20[FE]=20=EB=A9=94=EB=89=B4=20?= =?UTF-8?q?=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=ED=8E=98=EC=9D=B4=EC=A7=80=20?= =?UTF-8?q?=EA=B8=B0=EB=B3=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 페이지 기본 구성 - 카페별 메뉴 api 요청 #67 --- packages/client/src/Router.tsx | 10 +++--- .../client/src/pages/MenuList/index.spec.tsx | 1 + packages/client/src/pages/MenuList/index.tsx | 35 +++++++++++++++++++ packages/client/src/pages/MenuList/styled.ts | 1 + packages/client/src/types/MenuList.ts | 12 +++++++ 5 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 packages/client/src/pages/MenuList/index.spec.tsx create mode 100644 packages/client/src/pages/MenuList/index.tsx create mode 100644 packages/client/src/pages/MenuList/styled.ts create mode 100644 packages/client/src/types/MenuList.ts diff --git a/packages/client/src/Router.tsx b/packages/client/src/Router.tsx index eb7cd8b..ff579d6 100644 --- a/packages/client/src/Router.tsx +++ b/packages/client/src/Router.tsx @@ -1,7 +1,8 @@ import { Route, Routes } from 'react-router-dom'; -import Signup from './pages/Signup'; -import Signin from './pages/Signin'; -import OrderList from './pages/customer/OrderList'; +import Signup from 'pages/Signup'; +import Signin from 'pages/Signin'; +import OrderList from 'pages/customer/OrderList'; +import MenuList from 'pages/MenuList'; function Router() { return ( @@ -10,7 +11,8 @@ function Router() { }> {/* 회원가입 */} }> {/* 마이페이지 */} }> {/* 고객 메인 */} - }> {/* 고객 메뉴 목록 */} + }>{' '} + {/* 고객 메뉴 목록 */} }>{' '} {/* 고객 메뉴 상세 */} }> {/* 고객 장바구니 */} diff --git a/packages/client/src/pages/MenuList/index.spec.tsx b/packages/client/src/pages/MenuList/index.spec.tsx new file mode 100644 index 0000000..d78e7f1 --- /dev/null +++ b/packages/client/src/pages/MenuList/index.spec.tsx @@ -0,0 +1 @@ +import { render, screen, fireEvent, waitFor } from '@testing-library/react'; \ No newline at end of file diff --git a/packages/client/src/pages/MenuList/index.tsx b/packages/client/src/pages/MenuList/index.tsx new file mode 100644 index 0000000..01c2747 --- /dev/null +++ b/packages/client/src/pages/MenuList/index.tsx @@ -0,0 +1,35 @@ +import axios from 'axios'; +import { useState, useEffect } from 'react'; +import { CafeMenu } from 'types/MenuList'; + +function MenuList() { + const api = process.env.REACT_APP_API_SERVER_BASE_URL; + const [menuList, setMenuList] = useState(); + + const fetchMenuList = async () => { + try { + const res = await axios.get(`${api}/cafe/1/menus`, { withCredentials: true }); + setMenuList(res.data); + } catch (err) { + console.log(err); + } + }; + + useEffect(() => { + fetchMenuList(); + }, []); + + return (
+
    + {menuList?.menus.map(menu => ( +
  • + 메뉴 이미지 +

    {menu.name}

    +

    {menu.price}

    +
  • + ))} +
+
); +} + +export default MenuList; diff --git a/packages/client/src/pages/MenuList/styled.ts b/packages/client/src/pages/MenuList/styled.ts new file mode 100644 index 0000000..2bf8583 --- /dev/null +++ b/packages/client/src/pages/MenuList/styled.ts @@ -0,0 +1 @@ +import styled from '@emotion/styled'; \ No newline at end of file diff --git a/packages/client/src/types/MenuList.ts b/packages/client/src/types/MenuList.ts new file mode 100644 index 0000000..30076e7 --- /dev/null +++ b/packages/client/src/types/MenuList.ts @@ -0,0 +1,12 @@ +interface Menu { + id: number; + name: string; + thumbnail: string; + price: number; +} + +export interface CafeMenu { + id: number; + cafe_name: string; + menus: Menu[]; +} From 17776b3a3f27191be3c86c2825a40934d4e82745 Mon Sep 17 00:00:00 2001 From: Gon Kim Date: Mon, 21 Nov 2022 14:01:26 +0900 Subject: [PATCH 036/149] =?UTF-8?q?refactor:=20[BE]=20user/auth=20service?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 로그인/회원가입의 경우 auth로 진입 - auth에서 user service 호출하도록 module 의존 관계 수정 - user에서는 db에 요청을 날리는 부분을 service로 감싸, auth에서 쓸 수 있도록 제공 --- packages/server/src/auth/auth.controller.ts | 18 +------ packages/server/src/auth/auth.service.ts | 54 ++++++++++++++++++--- packages/server/src/user/user.module.ts | 5 +- packages/server/src/user/user.service.ts | 49 ++----------------- 4 files changed, 54 insertions(+), 72 deletions(-) diff --git a/packages/server/src/auth/auth.controller.ts b/packages/server/src/auth/auth.controller.ts index 7b0f1b9..553d685 100644 --- a/packages/server/src/auth/auth.controller.ts +++ b/packages/server/src/auth/auth.controller.ts @@ -28,28 +28,14 @@ export class AuthController { @Req() req: Request, @Query() naverSignInDto: NaverSignInDto ) { - return await this.userService.naverSignIn(req, naverSignInDto); + return await this.authService.naverSignIn(req, naverSignInDto); } // 회원가입 @Post('/signup') @HttpCode(201) async signUp(@Req() req: Request, @Body() signUpDto: SignUpDto) { - return await this.userService.signUp(req, signUpDto); - } - - // 로그아웃 - @Post('/signout') - signOut() { - const jwt = 'jwt'; - return this.userService.signOut(jwt); - } - - // 회원 탈퇴 - @Delete() - remove() { - const jwt = 'jwt'; - return this.userService.remove(jwt); + return await this.authService.signUp(req, signUpDto); } // 유저 권한 확인 diff --git a/packages/server/src/auth/auth.service.ts b/packages/server/src/auth/auth.service.ts index 78ddb7f..f87584c 100644 --- a/packages/server/src/auth/auth.service.ts +++ b/packages/server/src/auth/auth.service.ts @@ -4,22 +4,62 @@ import { Request } from 'express'; import { USER_TYPE } from 'src/user/enum/userType.enum'; import { JwtPayload } from './interfaces/jwtPayload'; import jwt from 'jsonwebtoken'; +import { NaverSignInDto } from './dto/naver-singIn.dto'; +import { User } from 'src/user/entities/user.entity'; +import { UserService } from 'src/user/user.service'; +import { SignUpDto } from './dto/signup.dto'; @Injectable() export class AuthService { - constructor(private readonly httpService: HttpService) {} + constructor( + private readonly httpService: HttpService, + private readonly userService: UserService + ) {} - async getUserInfoFromNaver(code: string, state: string) { + async naverSignIn(req: Request, naverSignInDto: NaverSignInDto) { + const { code, state } = naverSignInDto; + const { email, name } = await this._getUserInfoFromNaver(code, state); + + const user: User | null = await this.userService.findOneByEmail(email); + + if (user) { + const userType: USER_TYPE = user.role; + const tokens = this._setJwt(user.id, userType); + return tokens; + } else { + this._setSession(req, email, name); + throw new HttpException('no user data found', HttpStatus.SEE_OTHER); + } + } + + async signUp(req: Request, signUpDto: SignUpDto) { + const userInfoFromSession = this._getUserInfoFromSession(req); + const { userType } = signUpDto; + + let user; + if (userType == USER_TYPE.CLIENT) { + user = User.createClient({ ...userInfoFromSession, ...signUpDto }); + } else { + user = User.createManager({ ...userInfoFromSession, ...signUpDto }); + } + + await this.userService.create(user); + + const tokens = this._setJwt(user.id, userType); + return tokens; + } + + private async _getUserInfoFromNaver(code: string, state: string) { const { access_token } = await this._getTokens(code, state); return await this._getUserInfo(access_token); } - setSession(req: Request, email: string, name: string) { + private _setSession(req: Request, email: string, name: string) { const session: any = req.session; session.name = name; session.email = email; } - getUserInfoFromSession(req: Request) { + private _getUserInfoFromSession(req: Request) { const session: any = req.session; const { name, email } = session; if (name === undefined || email === undefined) { @@ -31,7 +71,7 @@ export class AuthService { return { name, email }; } - setJwt(id: number, userType: USER_TYPE) { + private _setJwt(id: number, userType: USER_TYPE) { const payload: JwtPayload = { id, userType }; const accessToken = jwt.sign(payload, 'temp_jwt_secret', { expiresIn: '1h', @@ -44,7 +84,7 @@ export class AuthService { return { accessToken, refreshToken }; } - async _getTokens(code: string, state: string) { + private async _getTokens(code: string, state: string) { const redirectURI = encodeURI(process.env.CLIENT_URI); const clientId = process.env.CLIENT_ID; @@ -72,7 +112,7 @@ export class AuthService { return apiRes.data; } - async _getUserInfo(access_token: string) { + private async _getUserInfo(access_token: string) { const api_url = 'https://openapi.naver.com/v1/nid/me'; const apiRes = await this.httpService.axiosRef.get(api_url, { headers: { diff --git a/packages/server/src/user/user.module.ts b/packages/server/src/user/user.module.ts index 8e2fe9e..bd4f58c 100644 --- a/packages/server/src/user/user.module.ts +++ b/packages/server/src/user/user.module.ts @@ -3,12 +3,11 @@ import { UserService } from './user.service'; import { UserController } from './user.controller'; import { TypeOrmModule } from '@nestjs/typeorm'; import { User } from './entities/user.entity'; -import { AuthModule } from 'src/auth/auth.module'; @Module({ - imports: [TypeOrmModule.forFeature([User]), AuthModule], + imports: [TypeOrmModule.forFeature([User])], controllers: [UserController], providers: [UserService], - // exports: [UserService], // User repository 만든걸 다른 곳에서도 사용하고 싶은 경우 + exports: [UserService], // User repository 만든걸 다른 곳에서도 사용하고 싶은 경우 }) export class UserModule {} diff --git a/packages/server/src/user/user.service.ts b/packages/server/src/user/user.service.ts index de00b98..46b2755 100644 --- a/packages/server/src/user/user.service.ts +++ b/packages/server/src/user/user.service.ts @@ -16,55 +16,12 @@ export class UserService { @InjectRepository(User) private userRepository: Repository ) {} - async naverSignIn(req: Request, naverSignInDto: NaverSignInDto) { - const { code, state } = naverSignInDto; - const { email, name } = await this.authService.getUserInfoFromNaver( - code, - state - ); - + async findOneByEmail(email: string) { const user: User | null = await this.userRepository.findOneBy({ email }); - - if (user) { - const userType: USER_TYPE = user.role; - const tokens = this.authService.setJwt(user.id, userType); - return tokens; - } else { - this.authService.setSession(req, email, name); - throw new HttpException('no user data found', HttpStatus.SEE_OTHER); - } + return user; } - async signUp(req: Request, signUpDto: SignUpDto) { - const userInfoFromSession = this.authService.getUserInfoFromSession(req); - const { userType } = signUpDto; - - let user; - if (userType == USER_TYPE.CLIENT) { - user = User.createClient({ ...userInfoFromSession, ...signUpDto }); - } else { - user = User.createManager({ ...userInfoFromSession, ...signUpDto }); - } - + async create(user: User) { await this.userRepository.save(user); - - const tokens = this.authService.setJwt(user.id, userType); - return tokens; - } - - signOut(jwt: string) { - return 'This action signs out a user'; - } - - update(updateUserDto: UpdateUserDto) { - return `This action updates a user`; - } - - remove(jwt: string) { - return `This action removes a user`; - } - - checkUser(jwt: string) { - return; } } From 2ef1f2caef82a5c1d5445f262ab3d400f75f4f63 Mon Sep 17 00:00:00 2001 From: qmdl980 Date: Mon, 21 Nov 2022 14:04:43 +0900 Subject: [PATCH 037/149] =?UTF-8?q?feat:=20[FE]=20MenuItem=20=EC=BB=B4?= =?UTF-8?q?=ED=8F=AC=EB=84=8C=ED=8A=B8=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/src/components/MenuItem/index.tsx | 20 +++++++++++++ .../client/src/components/MenuItem/styled.ts | 1 + packages/client/src/pages/MenuList/index.tsx | 29 ++++++++++++------- packages/client/src/types/MenuList.ts | 2 +- 4 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 packages/client/src/components/MenuItem/index.tsx create mode 100644 packages/client/src/components/MenuItem/styled.ts diff --git a/packages/client/src/components/MenuItem/index.tsx b/packages/client/src/components/MenuItem/index.tsx new file mode 100644 index 0000000..1726330 --- /dev/null +++ b/packages/client/src/components/MenuItem/index.tsx @@ -0,0 +1,20 @@ +import { useNavigate } from 'react-router-dom'; +import { Menu } from '@/types/MenuList'; + +function MenuItem(props: Menu) { + const navigate = useNavigate(); + + const handleClickMenuItem = () => { + navigate(`/menu/${props.id}`); + }; + + return ( +
  • + 메뉴 이미지 +

    {props.name}

    +

    {props.price}

    +
  • + ); +} + +export default MenuItem; diff --git a/packages/client/src/components/MenuItem/styled.ts b/packages/client/src/components/MenuItem/styled.ts new file mode 100644 index 0000000..6dcebd7 --- /dev/null +++ b/packages/client/src/components/MenuItem/styled.ts @@ -0,0 +1 @@ +import styled from "@emotion/styled"; \ No newline at end of file diff --git a/packages/client/src/pages/MenuList/index.tsx b/packages/client/src/pages/MenuList/index.tsx index 01c2747..fec2186 100644 --- a/packages/client/src/pages/MenuList/index.tsx +++ b/packages/client/src/pages/MenuList/index.tsx @@ -1,6 +1,7 @@ import axios from 'axios'; import { useState, useEffect } from 'react'; import { CafeMenu } from 'types/MenuList'; +import MenuItem from 'components/MenuItem'; function MenuList() { const api = process.env.REACT_APP_API_SERVER_BASE_URL; @@ -8,7 +9,9 @@ function MenuList() { const fetchMenuList = async () => { try { - const res = await axios.get(`${api}/cafe/1/menus`, { withCredentials: true }); + const res = await axios.get(`${api}/cafe/1/menus`, { + withCredentials: true, + }); setMenuList(res.data); } catch (err) { console.log(err); @@ -19,17 +22,21 @@ function MenuList() { fetchMenuList(); }, []); - return (
    -
      - {menuList?.menus.map(menu => ( -
    • - 메뉴 이미지 -

      {menu.name}

      -

      {menu.price}

      -
    • + return ( +
      +
        + {menuList?.menus.map((menu) => ( + ))} -
      -
      ); +
    +
    + ); } export default MenuList; diff --git a/packages/client/src/types/MenuList.ts b/packages/client/src/types/MenuList.ts index 30076e7..8af8c3e 100644 --- a/packages/client/src/types/MenuList.ts +++ b/packages/client/src/types/MenuList.ts @@ -1,4 +1,4 @@ -interface Menu { +export interface Menu { id: number; name: string; thumbnail: string; From e537a871482a7871ffef16141f3ca2f289b4090a Mon Sep 17 00:00:00 2001 From: Gon Kim Date: Mon, 21 Nov 2022 14:14:53 +0900 Subject: [PATCH 038/149] =?UTF-8?q?chore:=20[BE]=20passport,=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20jwt=20=EB=AA=A8=EB=93=88=20=EC=84=A4=EC=B9=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/server/package.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/server/package.json b/packages/server/package.json index f8466ba..d88e37a 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -25,7 +25,9 @@ "@nestjs/common": "^9.0.0", "@nestjs/config": "^2.2.0", "@nestjs/core": "^9.0.0", + "@nestjs/jwt": "^9.0.0", "@nestjs/mapped-types": "*", + "@nestjs/passport": "^9.0.0", "@nestjs/platform-express": "^9.0.0", "@nestjs/typeorm": "^9.0.1", "class-transformer": "^0.5.1", @@ -33,8 +35,9 @@ "cross-env": "^7.0.3", "docker-compose": "^0.23.17", "express-session": "^1.17.3", - "jsonwebtoken": "^8.5.1", "mysql2": "^2.3.3", + "passport": "^0.6.0", + "passport-jwt": "^4.0.0", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", "rxjs": "^7.2.0", @@ -49,6 +52,7 @@ "@types/jest": "28.1.8", "@types/jsonwebtoken": "^8.5.9", "@types/node": "^16.0.0", + "@types/passport-jwt": "^3.0.7", "@types/supertest": "^2.0.11", "@typescript-eslint/eslint-plugin": "^5.0.0", "@typescript-eslint/parser": "^5.0.0", From 591c71bbb64cdb51e765b8a66bc3cb4d931f3487 Mon Sep 17 00:00:00 2001 From: Gon Kim Date: Mon, 21 Nov 2022 14:22:58 +0900 Subject: [PATCH 039/149] =?UTF-8?q?refactor:=20[BE]=20=EA=B8=B0=EC=A1=B4?= =?UTF-8?q?=20jwt=20=EB=B0=9C=EA=B8=89=20=EB=A1=9C=EC=A7=81=EC=9D=84=20pas?= =?UTF-8?q?sport=20=EC=82=AC=EC=9A=A9=ED=95=98=EB=8A=94=20=EA=B2=83?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=8C=80=EC=B2=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - jwt module을 auth module에 등록 - 기존 _setJWT 함수에서 jwt 발급하는 부분 passport로 대체 --- packages/server/src/auth/auth.module.ts | 12 +++++++++++- packages/server/src/auth/auth.service.ts | 15 +++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/server/src/auth/auth.module.ts b/packages/server/src/auth/auth.module.ts index 9a32c24..3a901f7 100644 --- a/packages/server/src/auth/auth.module.ts +++ b/packages/server/src/auth/auth.module.ts @@ -3,9 +3,19 @@ import { HttpModule } from '@nestjs/axios'; import { AuthService } from './auth.service'; import { AuthController } from './auth.controller'; import { UserModule } from 'src/user/user.module'; +import { PassportModule } from '@nestjs/passport'; +import { JwtModule } from '@nestjs/jwt'; @Module({ - imports: [HttpModule, UserModule], + imports: [ + HttpModule, + UserModule, + PassportModule, + JwtModule.register({ + secret: process.env.JWT_SECRET, + signOptions: { expiresIn: '1h', issuer: 'buddah.com' }, + }), + ], controllers: [AuthController], providers: [AuthService], exports: [AuthService], diff --git a/packages/server/src/auth/auth.service.ts b/packages/server/src/auth/auth.service.ts index f87584c..f4e7ec2 100644 --- a/packages/server/src/auth/auth.service.ts +++ b/packages/server/src/auth/auth.service.ts @@ -8,11 +8,13 @@ import { NaverSignInDto } from './dto/naver-singIn.dto'; import { User } from 'src/user/entities/user.entity'; import { UserService } from 'src/user/user.service'; import { SignUpDto } from './dto/signup.dto'; +import { JwtService } from '@nestjs/jwt'; @Injectable() export class AuthService { constructor( private readonly httpService: HttpService, - private readonly userService: UserService + private readonly userService: UserService, + private readonly jwtService: JwtService ) {} async naverSignIn(req: Request, naverSignInDto: NaverSignInDto) { @@ -73,15 +75,8 @@ export class AuthService { private _setJwt(id: number, userType: USER_TYPE) { const payload: JwtPayload = { id, userType }; - const accessToken = jwt.sign(payload, 'temp_jwt_secret', { - expiresIn: '1h', - issuer: 'buddah.com', - }); - const refreshToken = jwt.sign({ id, userType }, 'temp_jwt_secret', { - expiresIn: '7d', - issuer: 'buddah.com', - }); - return { accessToken, refreshToken }; + const accessToken = this.jwtService.sign(payload); + return { accessToken }; } private async _getTokens(code: string, state: string) { From 7e860e2056fa929e13eeee00407c6edec8fc5fdd Mon Sep 17 00:00:00 2001 From: unho-00 Date: Mon, 21 Nov 2022 14:31:16 +0900 Subject: [PATCH 040/149] =?UTF-8?q?fix:=20[FE]=20Conflict=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=EC=98=A4=EB=A5=98=20=EC=9E=AC=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - axios 중복 import 제거 --- packages/client/src/pages/Signin/index.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/client/src/pages/Signin/index.tsx b/packages/client/src/pages/Signin/index.tsx index 7ad00fe..e82ec83 100644 --- a/packages/client/src/pages/Signin/index.tsx +++ b/packages/client/src/pages/Signin/index.tsx @@ -1,7 +1,6 @@ import axios, { AxiosError } from 'axios'; import { useCallback } from 'react'; import { useNavigate, useSearchParams } from 'react-router-dom'; -import axios, { AxiosError } from 'axios'; import { chkUser } from 'types/Signin'; import { Container, Logo, NaverOAuth } from './styled'; From 251c7f6bf87a7301b9b72d4c06ac5b20fc14291a Mon Sep 17 00:00:00 2001 From: unho-00 Date: Mon, 21 Nov 2022 14:35:05 +0900 Subject: [PATCH 041/149] =?UTF-8?q?feat:=20[FE]=20=EB=A9=94=EB=89=B4=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=EB=9D=BC?= =?UTF-8?q?=EC=9A=B0=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/client/src/Router.tsx | 4 ++-- packages/client/src/pages/customer/MenuDetail/index.tsx | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 packages/client/src/pages/customer/MenuDetail/index.tsx diff --git a/packages/client/src/Router.tsx b/packages/client/src/Router.tsx index eb7cd8b..66f8d9a 100644 --- a/packages/client/src/Router.tsx +++ b/packages/client/src/Router.tsx @@ -2,6 +2,7 @@ import { Route, Routes } from 'react-router-dom'; import Signup from './pages/Signup'; import Signin from './pages/Signin'; import OrderList from './pages/customer/OrderList'; +import MenuDetail from './pages/customer/MenuDetail'; function Router() { return ( @@ -11,8 +12,7 @@ function Router() { }> {/* 마이페이지 */} }> {/* 고객 메인 */} }> {/* 고객 메뉴 목록 */} - }>{' '} - {/* 고객 메뉴 상세 */} + }> }> {/* 고객 장바구니 */} {/* 업주 (전역 상태 관리로 고객과 함께 사용 가능) */} }> diff --git a/packages/client/src/pages/customer/MenuDetail/index.tsx b/packages/client/src/pages/customer/MenuDetail/index.tsx new file mode 100644 index 0000000..4c761c5 --- /dev/null +++ b/packages/client/src/pages/customer/MenuDetail/index.tsx @@ -0,0 +1,5 @@ +function MenuDetail() { + return <>; +} + +export default MenuDetail; From f767f6ddb0791739f68fa2a71430cd1b014cf028 Mon Sep 17 00:00:00 2001 From: Gon Kim Date: Mon, 21 Nov 2022 14:42:00 +0900 Subject: [PATCH 042/149] =?UTF-8?q?feat:=20[BE]=20passport=20jwt=20strateg?= =?UTF-8?q?y=20=EB=B0=8F=20guard=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - jwt의 경우 access token만 발급하며, 현재는 json으로 내려준다 --- packages/server/src/auth/auth.module.ts | 3 ++- packages/server/src/auth/guard/jwt.guard.ts | 5 +++++ .../server/src/auth/strategy/jwt.strategy.ts | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 packages/server/src/auth/guard/jwt.guard.ts create mode 100644 packages/server/src/auth/strategy/jwt.strategy.ts diff --git a/packages/server/src/auth/auth.module.ts b/packages/server/src/auth/auth.module.ts index 3a901f7..6622b9c 100644 --- a/packages/server/src/auth/auth.module.ts +++ b/packages/server/src/auth/auth.module.ts @@ -5,6 +5,7 @@ import { AuthController } from './auth.controller'; import { UserModule } from 'src/user/user.module'; import { PassportModule } from '@nestjs/passport'; import { JwtModule } from '@nestjs/jwt'; +import { JwtStrategy } from './strategy/jwt.strategy'; @Module({ imports: [ @@ -17,7 +18,7 @@ import { JwtModule } from '@nestjs/jwt'; }), ], controllers: [AuthController], - providers: [AuthService], + providers: [AuthService, JwtStrategy], exports: [AuthService], }) export class AuthModule {} diff --git a/packages/server/src/auth/guard/jwt.guard.ts b/packages/server/src/auth/guard/jwt.guard.ts new file mode 100644 index 0000000..f65f845 --- /dev/null +++ b/packages/server/src/auth/guard/jwt.guard.ts @@ -0,0 +1,5 @@ +import { Injectable } from '@nestjs/common'; +import { AuthGuard } from '@nestjs/passport'; + +@Injectable() +export class JwtGuard extends AuthGuard('jwt') {} diff --git a/packages/server/src/auth/strategy/jwt.strategy.ts b/packages/server/src/auth/strategy/jwt.strategy.ts new file mode 100644 index 0000000..f38f523 --- /dev/null +++ b/packages/server/src/auth/strategy/jwt.strategy.ts @@ -0,0 +1,16 @@ +import { PassportStrategy } from '@nestjs/passport'; +import { ExtractJwt, Strategy } from 'passport-jwt'; + +export class JwtStrategy extends PassportStrategy(Strategy) { + constructor() { + super({ + jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), + ignoreExpiration: false, + secretKey: process.env.JWT_SECRET, + }); + } + + async validate(payload) { + return { id: payload.id, userType: payload.userType }; + } +} From 384befc035436f63b66ac791e64d582918639dcf Mon Sep 17 00:00:00 2001 From: Gon Kim Date: Mon, 21 Nov 2022 14:59:55 +0900 Subject: [PATCH 043/149] =?UTF-8?q?refactor:=20[BE]=20jwt=20=EC=BF=A0?= =?UTF-8?q?=ED=82=A4=EC=97=90=20=EB=8B=B4=EC=95=84=EC=A3=BC=EB=8A=94=20?= =?UTF-8?q?=EA=B2=83=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/server/package.json | 2 ++ packages/server/src/auth/auth.controller.ts | 15 ++++++++++++--- packages/server/src/auth/strategy/jwt.strategy.ts | 6 +++++- packages/server/src/main.ts | 2 ++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/packages/server/package.json b/packages/server/package.json index d88e37a..86aabef 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -32,6 +32,7 @@ "@nestjs/typeorm": "^9.0.1", "class-transformer": "^0.5.1", "class-validator": "^0.13.2", + "cookie-parser": "^1.4.6", "cross-env": "^7.0.3", "docker-compose": "^0.23.17", "express-session": "^1.17.3", @@ -47,6 +48,7 @@ "@nestjs/cli": "^9.0.0", "@nestjs/schematics": "^9.0.0", "@nestjs/testing": "^9.0.0", + "@types/cookie-parser": "^1.4.3", "@types/express": "^4.17.13", "@types/express-session": "^1.17.5", "@types/jest": "28.1.8", diff --git a/packages/server/src/auth/auth.controller.ts b/packages/server/src/auth/auth.controller.ts index 553d685..36717a3 100644 --- a/packages/server/src/auth/auth.controller.ts +++ b/packages/server/src/auth/auth.controller.ts @@ -7,11 +7,12 @@ import { HttpCode, Query, Req, + Res, } from '@nestjs/common'; import { SignUpDto } from '../auth/dto/signup.dto'; import { NaverSignInDto } from '../auth/dto/naver-singIn.dto'; -import { Request } from 'express'; +import { Request, Response } from 'express'; import { AuthService } from './auth.service'; import { UserService } from 'src/user/user.service'; @@ -26,9 +27,17 @@ export class AuthController { @Get('/naver-oauth') async naverSignIn( @Req() req: Request, - @Query() naverSignInDto: NaverSignInDto + @Query() naverSignInDto: NaverSignInDto, + @Res() res: Response ) { - return await this.authService.naverSignIn(req, naverSignInDto); + const { accessToken } = await this.authService.naverSignIn( + req, + naverSignInDto + ); + res.cookie('accessToken', accessToken, { + httpOnly: true, + }); + return; } // 회원가입 diff --git a/packages/server/src/auth/strategy/jwt.strategy.ts b/packages/server/src/auth/strategy/jwt.strategy.ts index f38f523..1839cbb 100644 --- a/packages/server/src/auth/strategy/jwt.strategy.ts +++ b/packages/server/src/auth/strategy/jwt.strategy.ts @@ -4,7 +4,11 @@ import { ExtractJwt, Strategy } from 'passport-jwt'; export class JwtStrategy extends PassportStrategy(Strategy) { constructor() { super({ - jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), + jwtFromRequest: ExtractJwt.fromExtractors([ + (request) => { + return request?.cookies?.accessToken; + }, + ]), ignoreExpiration: false, secretKey: process.env.JWT_SECRET, }); diff --git a/packages/server/src/main.ts b/packages/server/src/main.ts index d24a37b..cad0991 100644 --- a/packages/server/src/main.ts +++ b/packages/server/src/main.ts @@ -1,6 +1,7 @@ import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; import session from 'express-session'; +import cookieParser from 'cookie-parser'; async function bootstrap() { const app = await NestFactory.create(AppModule); @@ -8,6 +9,7 @@ async function bootstrap() { origin: process.env.CLIENT_URI, credentials: true, }); + app.use(cookieParser()); app.use( session({ secret: 'buddah!@#$', From 73c8f01c7a3a1f2781852dff45558a47e05f5491 Mon Sep 17 00:00:00 2001 From: qmdl980 Date: Mon, 21 Nov 2022 15:15:03 +0900 Subject: [PATCH 044/149] =?UTF-8?q?feat:=20[FE]=20Footer=20=EA=B8=B0?= =?UTF-8?q?=EB=B3=B8=20=EA=B5=AC=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 기본 레이아웃 구성 - 페이지 이동 구현 #71 --- .../client/src/components/Footer/index.tsx | 58 +++++++++++++++++++ .../client/src/components/Footer/styled.ts | 28 +++++++++ packages/client/src/pages/MenuList/index.tsx | 2 + 3 files changed, 88 insertions(+) create mode 100644 packages/client/src/components/Footer/index.tsx create mode 100644 packages/client/src/components/Footer/styled.ts diff --git a/packages/client/src/components/Footer/index.tsx b/packages/client/src/components/Footer/index.tsx new file mode 100644 index 0000000..1a4a3de --- /dev/null +++ b/packages/client/src/components/Footer/index.tsx @@ -0,0 +1,58 @@ +import { useState, useEffect } from 'react'; +import { useNavigate, useLocation } from 'react-router-dom'; +import { FooterWrapper, NavWrapper } from './styled'; + +function Footer() { + const navigate = useNavigate(); + const location = useLocation(); + const [currentPath, setCurrentPath] = useState(); + + const handleClickHome = (e: React.MouseEvent) => { + navigate('/home'); + }; + + const handleClickOrder = (e: React.MouseEvent) => { + navigate('/menu'); + }; + + const handleClickMY = (e: React.MouseEvent) => { + navigate('/mypage'); + }; + + const findPath = () => { + if (/home/.test(location.pathname)) setCurrentPath('home'); + else if (/menu|order/.test(location.pathname)) setCurrentPath('order'); + else if (/mypage/.test(location.pathname)) setCurrentPath('mypage'); + }; + + useEffect(() => { + findPath(); + }, []); + + return ( + + +

    + Home +

    +

    + Order +

    +

    + MY +

    +
    +
    + ); +} + +export default Footer; diff --git a/packages/client/src/components/Footer/styled.ts b/packages/client/src/components/Footer/styled.ts new file mode 100644 index 0000000..855c559 --- /dev/null +++ b/packages/client/src/components/Footer/styled.ts @@ -0,0 +1,28 @@ +import styled from '@emotion/styled'; + +export const FooterWrapper = styled.footer` + position: fixed; + left: 0; + bottom: 0; + width: 100%; + height: 3rem; + box-shadow: 0px 0px 4px rgba(204, 204, 204, 0.5), + 0px 0px 4px rgba(0, 0, 0, 0.25); +`; + +export const NavWrapper = styled.nav` + display: flex; + flex-direction: row; + justify-content: space-evenly; + align-items: center; + width: 100%; + height: 100%; + + p{ + color: ${(props) => props.theme.colors.tertiary}; + } + + p.selected{ + color: ${(props) => props.theme.colors.primary}; + } +` diff --git a/packages/client/src/pages/MenuList/index.tsx b/packages/client/src/pages/MenuList/index.tsx index fec2186..8bd1c36 100644 --- a/packages/client/src/pages/MenuList/index.tsx +++ b/packages/client/src/pages/MenuList/index.tsx @@ -2,6 +2,7 @@ import axios from 'axios'; import { useState, useEffect } from 'react'; import { CafeMenu } from 'types/MenuList'; import MenuItem from 'components/MenuItem'; +import Footer from '@/components/Footer'; function MenuList() { const api = process.env.REACT_APP_API_SERVER_BASE_URL; @@ -35,6 +36,7 @@ function MenuList() { /> ))} +