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

66.66% Statements 40/60
100% Branches 3/3
42.85% Functions 3/7
66.66% Lines 40/60

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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 611x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x             6x 6x 6x     6x 6x 6x 2x 2x 2x 2x 6x 6x 6x             6x 6x 6x 1x 1x 1x 1x 6x 6x 6x             6x  
import { baseAPI } from '@/api/core/base';
import { refreshAPI } from '@/api/core/refresh';
import { clearAccessToken, setAccessToken } from '@/lib/auth/token';
import {
  GoogleOAuthExchangeRequest,
  GoogleOAuthExchangeResponse,
  LoginRequest,
  LoginResponse,
  RefreshResponse,
  SignupRequest,
  SignupResponse,
} from '@/types/service/auth';
 
export const authServiceRemote = () => ({
  // 로그인
  login: async (payload: LoginRequest) => {
    //prettier-ignore
    const data = await baseAPI.post<LoginResponse>('/api/v1/auth/login', payload, { withCredentials: true });

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

    setAccessToken(data.accessToken, data.expiresIn);
    return data;
  },
 
  // 회원 탈퇴
  withdraw: async () => {
    await baseAPI.delete<void>('/api/v1/auth/withdraw', { withCredentials: true });
 
    clearAccessToken();
  },
 
  // 구글 OAuth 코드 교환
  exchangeGoogleCode: async (payload: GoogleOAuthExchangeRequest) => {
    //prettier-ignore
    const data = await baseAPI.post<GoogleOAuthExchangeResponse>('/api/v1/auth/google', payload, { withCredentials: true });

    setAccessToken(data.accessToken, data.expiresIn);
    return data;
  },
});