Skip to content

Instantly share code, notes, and snippets.

@alejovdev
Created July 28, 2020 10:24
Show Gist options
  • Save alejovdev/fa37be11faf5c8760177b2ea563cad12 to your computer and use it in GitHub Desktop.
Save alejovdev/fa37be11faf5c8760177b2ea563cad12 to your computer and use it in GitHub Desktop.
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