Newer
Older
taehui / taehui-fe / src / avatar / useAutoLogIn.ts
@Taehui Taehui on 17 Mar 653 bytes 2024-03-17 오후 2:12
import usePostGetTotem from "@/avatar/usePostGetTotem";
import CryptoJS from "crypto-js";
import { useCallback } from "react";

export default function useAutoLogIn() {
  const { mutateAsync: postGetTotem } = usePostGetTotem();

  return useCallback(async () => {
    if (window.localStorage.getItem("autoLogIn") === "true") {
      await postGetTotem({
        avatarID: window.localStorage.getItem("avatarID") ?? "",
        avatarCipher: CryptoJS.AES.decrypt(
          window.localStorage.getItem("avatarCipher") ?? "",
          "591A6F91-2A27-4A88-88FA-0FEB7CB5FD94",
        ).toString(CryptoJS.enc.Utf8),
      });
    }
  }, [postGetTotem]);
}