Created
July 28, 2020 10:24
-
-
Save alejovdev/fa37be11faf5c8760177b2ea563cad12 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const [cookies, setCookie] = useCookies(['frbstkn', 'redirect']) | |
useEffect(() => { | |
auth.onAuthStateChanged((user) => { | |
if (user) getCustomToken() | |
}) | |
}, []) | |
const getCustomToken = async () => { | |
if (auth.currentUser === null) return | |
let fn = functions.httpsCallable('getUserToken') | |
let res = await fn({ uid: auth.currentUser.uid }) | |
if (res.data.error === true) return | |
setCookie('frbstkn', res.data.data, { | |
path: '/', | |
}) | |
if (cookies.redirect) window.location.replace(cookies.redirect) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment