24.3.3 로그아웃 기능 구현

    이번에는 로그아웃 기능을 구현해 봅시다. 로그아웃 기능을 구현하는 것은 간단합니다. 로그아웃 API를 호출하고, localStorage 안의 값을 없애 주면 됩니다.

    먼저 lib/api/auth.js 파일을 열어서 logout 함수를 만들어 주세요.

    lib/api/auth.js

    import client from './client';
    
    // 로그인
    export const login = ({ username, password }) =>
      client.post('/api/auth/login', { username, password });
    
    // 회원가입
    export const register = ({ username, password }) =>
      client.post('/api/auth/register', { username, password });
    
    // 로그인 상태 확인
    export const check = () => client.get('/api/auth/check');
    
    // 로그아웃
    export const logout = () => client.post('/api/auth/logout');

    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.