Skip to content

Commit

Permalink
Merge pull request #57 from ISTTP/develop
Browse files Browse the repository at this point in the history
에러 해결
  • Loading branch information
ieun32 authored Jul 18, 2024
2 parents dc3e6e6 + d76db58 commit c7e5d86
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/mainDeploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ jobs:
working-directory: ./apps/client
env:
SERVER_URL: ${{ secrets.SERVER_URL }}
KAKAO_JAVASCRIPT_KEY: ${{ secrets.KAKAO_JAVASCRIPT_KEY }}
KAKAO_JAVASCRIPT_KEY: ${{ secrets.KAKAO_JAVASCRIPT_KEY }

- name: build
run: pnpm turbo run build

Expand Down
10 changes: 6 additions & 4 deletions apps/client/src/components/cake/MyCake.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import Toggle from '#components/Toggle.tsx';
import GridInfo from '#components/GridInfo.tsx';
Expand Down Expand Up @@ -27,9 +27,11 @@ const MyCake: React.FC<MyCakeProps> = ({ ownerId, data }) => {
setOpen(!open);
}

if (!data.sheetColor || !data.creamColor) {
navigate(`/cake/create/${ownerId}`);
}
useEffect(() => {
if (!data.sheetColor || !data.creamColor) {
navigate(`/cake/create/${ownerId}`);
}
}, [data.sheetColor, data.creamColor]);

return (
<InnerWrapper>
Expand Down
12 changes: 9 additions & 3 deletions apps/client/src/pages/Cake.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import Wrapper from '#components/Wrapper.tsx';
import axiosInstance from '#apis/axios.ts';
import MyCake from '#components/cake/MyCake.tsx';
Expand All @@ -10,6 +11,7 @@ import { useParams } from 'react-router-dom';

const Cake = () => {
const { ownerId } = useParams();
const navigate = useNavigate();
const [isMyCake, setIsMyCake] = useState(false);
const [cakeUserData, setCakeUserData] = useState<getCakeRes>();

Expand All @@ -24,10 +26,10 @@ const Cake = () => {
}
} catch (error) {
if (error instanceof AxiosError) {
if (error.status === 401) {
if (error.response?.status === 401) {
setIsMyCake(false);
}
if (error.status === 500) {
if (error.response?.status === 500) {
alert('현재 유저 정보를 불러오는데 실패했습니다. 새로고침 해주세요.');
}
}
Expand All @@ -41,7 +43,11 @@ const Cake = () => {
setCakeUserData(result);
} catch (error) {
if (error instanceof AxiosError) {
if (error.status === 500) {
if (error.response?.status === 400) {
alert('잘못된 케이크 주소입니다.');
navigate('/');
}
if (error.response?.status === 500) {
alert(
'케이크 소유자 정보를 불러오는데 실패했습니다. 새로고침 해주세요.',
);
Expand Down
2 changes: 1 addition & 1 deletion apps/client/src/pages/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const Login = () => {
}
} catch (error) {
if (error instanceof AxiosError) {
if (error.status === 500) {
if (error.response?.status === 500) {
alert('오류가 발생했습니다, 새로고침 해주세요.');
}
}
Expand Down
12 changes: 8 additions & 4 deletions apps/server/src/routes/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import { user } from '@isttp/schemas/all';
const router: Router = Router();

router.get('/user/me', authorize, async (req, res) => {
const userId = req.userId;
const data = await getUser(userId);
const safe = user.parse(data);
res.status(200).json(safe);
try {
const userId = req.userId;
const data = await getUser(userId);
const safe = user.parse(data);
res.status(200).json(safe);
} catch (error) {
res.status(500).json({ message: `사용자 정보 조회 실패: ${error}` });
}
});

router.put('/user/me', authorize, async (req, res) => {
Expand Down
9 changes: 8 additions & 1 deletion apps/server/src/service/auth.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import axios from 'axios';
import qs from 'qs';

import prisma from '@isttp/db/all';
import { reissueToken, verifyToken, decodeToken } from '@isttp/utils/all';
import { GoogleTokenType, KakaoTokenType } from '@isttp/types/all';
import { NextFunction, Request, Response } from 'express';
import { getUser } from '../models/user';

export function setAuthCookies(
res: Response,
Expand Down Expand Up @@ -202,6 +202,13 @@ export async function authorize(

const { userId } = payload;

const data = await getUser(userId);
if (!data) {
res.clearCookie('ACT');
res.clearCookie('RFT');
return res.status(500).json({ message: '존재하지 않는 유저' });
}

const result = await checkValidation({
userId,
accessToken,
Expand Down

0 comments on commit c7e5d86

Please sign in to comment.