All files / src/api/service/auth-service index.ts

78.26% Statements 36/46
80% Branches 4/5
66.66% Functions 4/6
78.26% Lines 36/46

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 471x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x           6x 6x 6x 6x 6x 6x 2x 2x 2x 6x 6x 6x 6x 6x 6x 6x           6x 6x 6x 1x 1x 1x 6x  
import { api } from '@/api/core';
import { clearAccessToken, setAccessToken } from '@/lib/auth/token';
import {
  LoginRequest,
  LoginResponse,
  RefreshResponse,
  SignupRequest,
  SignupResponse,
} from '@/types/service/auth';
 
export const authServiceRemote = () => ({
  // 로그인
  login: async (payload: LoginRequest) => {
    const data = await api.post<LoginResponse>('/auth/login', payload, { withCredentials: true });

    setAccessToken(data.accessToken, data.expiresIn);
    return data;
  },
 
  // 회원가입
  signup: (payload: SignupRequest) => api.post<SignupResponse>(`/auth/signup`, payload),
 
  // 로그아웃
  logout: async () => {
    await api.post<void>('/auth/logout', null, { withCredentials: true });
    clearAccessToken();
  },
 
  // 액세스 토큰 재발급
  refresh: async () => {
    const data = await api.post<RefreshResponse>(
      '/auth/refresh',
      {},
      { _retry: true, withCredentials: true },
    );

    setAccessToken(data.accessToken, data.expiresIn);
    return data;
  },
 
  // 회원 탈퇴
  withdraw: async () => {
    await api.delete<void>('/auth/withdraw', { withCredentials: true });
    clearAccessToken();
  },
});