import { RegisterFormInput } from "../../components/auth/RegisterForm" ; import apiClient from "./apiClient" ; export interface ApiResponse < T > { response : string ; message : string ; data : T ; } export const register = async ( { username , password , member_group , member_name , member_rank , dog_tags , } ) => { const response = await apiClient . post < ApiResponse < string > > ( "/user/signup" , { username , password , member_group , member_name , member_rank , dog_tags , } ) ; apiClient . defaults . headers . common [ "Authorization" ] = response . data . data ; localStorage . setItem ( "accessToken" , response . data . data ) ; } ; export const login = async ( username , password ) => { const response = await apiClient . post < ApiResponse < string > > ( "/user/signin" , { username , password , } ) ; if ( response . data . response !== "success" ) { throw new Error ( response . data . message ) ; } apiClient . defaults . headers . common [ "Authorization" ] = response . data . data ; localStorage . setItem ( "accessToken" , response . data . data ) ; } ; export const logout = async ( ) => { await apiClient . post ( "/user/signout" ) ; delete apiClient . defaults . headers . common [ "Authorization" ] ; localStorage . removeItem ( "accessToken" ) ; } ;