All files / client/src/services loginServices.ts

100% Statements 20/20
100% Branches 0/0
100% Functions 7/7
100% Lines 20/20

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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87                                356x     24x   24x             23x     356x     315x           315x     356x 22x     356x 7x     356x     18x           18x     356x     15x           15x     356x     23x           24x    
import { api } from "client/utils/api";
import { LoginFormFields } from "client/views/login/components/LocalLoginForm";
import { ApiEndpoint, AuthEndpoint } from "shared/constants/apiEndpoints";
import {
  PostKompassiLoginRequest,
  PostKompassiLoginResponse,
  PostLoginRequest,
  PostLoginResponse,
  PostSessionRecoveryRequest,
  PostSessionRecoveryResponse,
  PostUpdateUserEmailAddressRequest,
  PostUpdateUserEmailAddressResponse,
  PostVerifyKompassiLoginRequest,
  PostVerifyKompassiLoginResponse,
} from "shared/types/api/login";
 
export const postLogin = async (
  loginFormFields: LoginFormFields,
): Promise<PostLoginResponse> => {
  const { username, password } = loginFormFields;
 
  const response = await api.post<PostLoginResponse, PostLoginRequest>(
    ApiEndpoint.LOGIN,
    {
      username,
      password,
    },
  );
  return response.data;
};
 
export const postSessionRecovery = async (
  jwt: string,
): Promise<PostSessionRecoveryResponse> => {
  const response = await api.post<
    PostSessionRecoveryResponse,
    PostSessionRecoveryRequest
  >(ApiEndpoint.SESSION_RESTORE, {
    jwt,
  });
  return response.data;
};
 
export const postKompassiLoginRedirect = async (): Promise<void> => {
  await api.post(AuthEndpoint.KOMPASSI_LOGIN);
};
 
export const postKompassiLogoutRedirect = async (): Promise<void> => {
  await api.post(AuthEndpoint.KOMPASSI_LOGOUT);
};
 
export const postKompassiLoginCallback = async (
  code: string,
): Promise<PostKompassiLoginResponse> => {
  const response = await api.post<
    PostKompassiLoginResponse,
    PostKompassiLoginRequest
  >(AuthEndpoint.KOMPASSI_LOGIN_CALLBACK, {
    code,
  });
  return response.data;
};
 
export const postVerifyKompassiLogin = async (
  username: string,
): Promise<PostVerifyKompassiLoginResponse> => {
  const response = await api.post<
    PostVerifyKompassiLoginResponse,
    PostVerifyKompassiLoginRequest
  >(ApiEndpoint.VERIFY_KOMPASSI_LOGIN, {
    username,
  });
  return response.data;
};
 
export const postUpdateUserEmailAddress = async (
  email: string,
): Promise<PostUpdateUserEmailAddressResponse> => {
  const response = await api.post<
    PostUpdateUserEmailAddressResponse,
    PostUpdateUserEmailAddressRequest
  >(ApiEndpoint.UPDATE_USER_EMAIL_ADDRESS, {
    email,
  });
  return response.data;
};