첫 커밋

This commit is contained in:
focp212@naver.com
2025-09-05 15:36:48 +09:00
commit 05238b04c1
825 changed files with 176358 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
import axios from 'axios';
import { API_URL } from '@/shared/api/urls';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import {
LoginParams,
LoginResponse
} from '../model/types';
import {
useMutation,
UseMutationOptions
} from '@tanstack/react-query';
export const login = (params: LoginParams) => {
return resultify(
axios.post<LoginResponse>(API_URL.login(), params),
);
};
export const useLoginMutation = (options?: UseMutationOptions<LoginResponse, CBDCAxiosError, LoginParams>) => {
const mutation = useMutation<LoginResponse, CBDCAxiosError, LoginParams>({
...options,
mutationFn: (params: LoginParams) => login(params),
});
return {
...mutation,
};
};

View File

@@ -0,0 +1,29 @@
import axios from 'axios';
import { API_URL } from '@/shared/api/urls';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import {
UserCreateParams,
UserCreateResponse
} from '../model/types';
import {
useMutation,
UseMutationOptions
} from '@tanstack/react-query';
export const userCreate = (params: UserCreateParams) => {
return resultify(
axios.post<UserCreateResponse>(API_URL.userCreate(), params),
);
};
export const useUserCreateMutation = (options?: UseMutationOptions<UserCreateResponse, CBDCAxiosError, UserCreateParams>) => {
const mutation = useMutation<UserCreateResponse, CBDCAxiosError, UserCreateParams>({
...options,
mutationFn: (params: UserCreateParams) => userCreate(params),
});
return {
...mutation,
};
};

View File

@@ -0,0 +1,29 @@
import axios from 'axios';
import { API_URL } from '@/shared/api/urls';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import {
UserExistsUseridParams,
UserExistsUseridResponse
} from '../model/types';
import {
useMutation,
UseMutationOptions
} from '@tanstack/react-query';
export const userExistsUserid = (params: UserExistsUseridParams) => {
return resultify(
axios.post<UserExistsUseridResponse>(API_URL.userExistsUserid(), params),
);
};
export const useUserExistsUseridMutation = (options?: UseMutationOptions<UserExistsUseridResponse, CBDCAxiosError, UserExistsUseridParams>) => {
const mutation = useMutation<UserExistsUseridResponse, CBDCAxiosError, UserExistsUseridParams>({
...options,
mutationFn: (params: UserExistsUseridParams) => userExistsUserid(params),
});
return {
...mutation,
};
};

View File

@@ -0,0 +1,50 @@
import { LoginParams } from '@/entities/user/model/types';
import { StorageKeys } from '@/shared/constants/local-storage';
import { setLocalStorage } from '@/shared/lib/web-view-bridge';
import { useLoginMutation } from '@/entities/user/api/use-login-mutation';
import { useStore } from '~/shared/model/store';
export const useUserInfo = () => {
const { mutateAsync: login } = useLoginMutation();
const callLogin = async (params: LoginParams) => {
try{
useStore.getState().UserStore.resetUserInfo();
const result = await login(params);
if(result.requires2FA){
// 2차인증 필요
}
else{
const {
tokenType,
accessToken,
refreshToken,
accessTokenExpiresIn,
refreshTokenExpiresIn,
menuGrants,
usrid,
clientAddressIP,
requires2FA
} = result;
setLocalStorage(StorageKeys.TokenType, tokenType);
setLocalStorage(StorageKeys.AccessToken, accessToken);
setLocalStorage(StorageKeys.RefreshToken, refreshToken);
setLocalStorage(StorageKeys.AccessTokenExpiresIn, accessTokenExpiresIn);
setLocalStorage(StorageKeys.RefreshTokenExpiresIn, refreshTokenExpiresIn);
setLocalStorage(StorageKeys.MenuGrants, menuGrants);
setLocalStorage(StorageKeys.Usrid, usrid);
setLocalStorage(StorageKeys.ClientAddressIP, clientAddressIP);
setLocalStorage(StorageKeys.Requires2FA, requires2FA);
useStore.getState().UserStore.setUserInfo(result);
}
}
catch(e: any){
}
};
return {
callLogin,
}
}

View File

@@ -0,0 +1,39 @@
import { lens } from '@dhmk/zustand-lens';
import { SetStateAction } from 'react';
import { UserInfo } from '@/entities/user/model/types';
import { StorageKeys } from '~/shared/constants/local-storage';
export interface UserInfoState {
UserInfo: UserInfo;
setUserInfo: (update: SetStateAction<Partial<UserInfo>>) => void;
resetUserInfo: () => void;
}
const initialState = {
UserInfo: {} as UserInfo,
} as UserInfoState;
export const createUserInfoStore = lens<UserInfoState>((set, get) => ({
...initialState,
setUserInfo: (update) => {
set((state: UserInfoState) => {
const newUserInfo = typeof update === 'function' ? update(state.UserInfo) : update;
return {
...state,
UserInfo: { ...state.UserInfo, ...newUserInfo },
};
});
},
resetUserInfo: () => {
window.localStorage.removeItem(StorageKeys.TokenType);
window.localStorage.removeItem(StorageKeys.AccessToken);
window.localStorage.removeItem(StorageKeys.RefreshToken);
window.localStorage.removeItem(StorageKeys.AccessTokenExpiresIn);
window.localStorage.removeItem(StorageKeys.RefreshTokenExpiresIn);
window.localStorage.removeItem(StorageKeys.MenuGrants);
window.localStorage.removeItem(StorageKeys.Usrid);
window.localStorage.removeItem(StorageKeys.ClientAddressIP);
window.localStorage.removeItem(StorageKeys.Requires2FA);
set(initialState);
},
}));

View File

@@ -0,0 +1,89 @@
export interface LoginParams {
id: string;
password: string;
};
export interface MenuGrantsItem {
menuId: number;
grant: number;
};
export interface LoginResponse {
tokenType?: string;
accessToken?: string;
refreshToken?: string;
accessTokenExpiresIn?: number;
refreshTokenExpiresIn?: number;
menuGrants?: Array<MenuGrantsItem>;
usrid?: string;
clientAddressIP?: string;
tempToken?: string,
tempTokenExpiresIn?: number;
available2FAMethod?: Array<string>;
requires2FA?: boolean;
};
export interface UserInfo extends LoginResponse{
}
export interface UserParams {
};
export interface UserExistsUseridParams {
usrId: string;
};
export interface UserExistsUseridResponse {
exists: boolean;
};
export interface VerificationsItem {
type: string;
contact: string;
};
export interface UserCreateParams {
userId: string;
password: string;
loginRange: string;
verification: Array<VerificationsItem>
};
export interface UserData {
usrid: string;
mid: string;
gid: string;
aid: string;
pw: string;
authCd: string;
status: string;
regDt: string;
memo: string;
changeDt: string;
failCnt: number;
oldPw1: string;
oldPw2: string;
oldPw3: string;
oldPw4: string;
worker: string;
loginCd: string;
pwWorkIp: string;
pwCheckYn: string;
loginFailDt: string;
loginFailTm: string;
loginFailIp: string;
desaYn: string;
desaAccType: string;
desaAccIp: string;
desaProcType: string;
desaFormat: string;
desaSvcCl: string;
emailAuth1: string;
emailAuth2: string;
emailAuth3: string;
authDt: string;
authTm: string;
userAidGroupYn: string;
userAidGroupId: string;
subNm: string;
subLevel: string;
multiAccessYn: string;
};
export interface UserCreateResponse {
user: UserData;
};