import { atom, useAtom } from 'jotai';
import { SetStateAction } from 'jotai';
// import { useEffect } from 'react';

const accessTokenAtom = atom<string | null>(null);

type SetAtom<Args extends unknown[], Result> = (...args: Args) => Result;
interface IUseAuth {
  accessToken: string | undefined | null;
  setAccessToken: SetAtom<[SetStateAction<string | null>], void>;
}

export default function useAuth(): IUseAuth {
  const [ accessToken, setAccessToken ] = useAtom(accessTokenAtom);
  // useEffect(() => {
  //   console.log(`atom accessToken: ${accessToken}`);
  // }, [accessToken, setAccessToken])
  return { accessToken, setAccessToken };
}