CoastalCommitsPastes/client/lib/hooks/use-signed-in.ts
2022-03-21 18:51:19 -07:00

19 lines
483 B
TypeScript

import Cookies from "js-cookie";
import { useEffect, useState } from "react";
const useSignedIn = () => {
const [signedIn, setSignedIn] = useState(typeof window === 'undefined' ? false : !!Cookies.get("drift-token"));
const token = Cookies.get("drift-token")
useEffect(() => {
if (token) {
setSignedIn(true);
} else {
setSignedIn(false);
}
}, [token]);
return { signedIn, token };
}
export default useSignedIn;