Skip to content

[Dev-log] 220301 김제완 #109

@Jaekomplett

Description

@Jaekomplett

오늘은 어떻게 프로젝트에 기여했나요?

  • 회원탈퇴 기능 구현

오늘의 프로젝트에서 힘든 점은 무엇인가요?

  • 회원탈퇴 요청을 보내는 것이 너무 힘들었다. 라우트에서 설정된 .route("/userInfo/:userId") 이 주소로 요청을 보내는 방법도 헷갈렸다..

userRoutes.js

router
  .route("/userInfo/:userId")
  .patch(updateProfile)
  .delete(deleteUser);
  • 회원탈퇴 요청을 할 때, 아래 유저의 토큰 검증하는 protect 함수에서 막혀서 오랫동안 시간을 쏟느라 모두가 힘들었다.

middleware/index.js

const jwt = require("jsonwebtoken");
const User = require("../models/user");

// 로그인 유저만 private route 접근을 허락해주는 함수
// 토큰 정보를 받아서 해독하고 검증한다.
module.exports = {
  protect: async (req, res, next) => {
    let token = req.cookies.x_auth;

    User.findByToken(token)
      .then((user) => {
        if (!user) return res.json({ isAuth: false, error: true });
        req.token = token;
        req.user = user;
        next();
      })
      .catch((err) => {
        throw err;
      });
  },
};
  • 요청을 보내는 코드는 서버 api 라우터와 동일하게 아래처럼 작성하니 정상적으로 요청, 응답이 이루어졌다.
  const navigate = useNavigate();
  const [isLogin, setIsLogin] = useRecoilState(IsLoginState);
  const config = {
    "Content-Type": "application/json",
    withCredentials: true,
  };
  const userId = localStorage.getItem('userId')

  const withdrawalHandler = () => {
    axios
      .delete(`http://localhost:27017/user/userInfo/${userId}`,
      config
      )
      .then(res => {
        console.log(res);
        localStorage.removeItem(userId);
        setIsLogin(false);
        alert("탈퇴");
        navigate('/');
      })
  }

내일은 프로젝트에 기여하기 위해 무엇을 해야 하나요?

  • Todo 형식으로 기록해주세요.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions