1
0
mirror of synced 2025-12-21 10:57:10 -05:00
Files
docs/components/hooks/useHasAccount.ts
Kevin Heis ca61b3465a Use color_mode for gating "sign up" button (#29901)
* Use color_mode for gating "sign up" button

* Update useHasAccount.ts

* Update useHasAccount.ts

* Update useHasAccount.ts
2022-08-12 18:18:58 +00:00

21 lines
804 B
TypeScript

import { useState, useEffect } from 'react'
import Cookies from 'js-cookie'
// Measure if the user has a github.com account and signed in during this session.
// The github.com sends the color_mode cookie every request when you sign in,
// but does not delete the color_mode cookie on sign out.
// You do not need to change your color mode settings to get this cookie,
// this applies to every user regardless of if they changed this setting.
// To test this, try a private browser tab.
// We are using the color_mode cookie because it is not HttpOnly.
export function useHasAccount() {
const [hasAccount, setHasAccount] = useState<boolean | null>(null)
useEffect(() => {
const cookieValue = Cookies.get('color_mode')
setHasAccount(Boolean(cookieValue))
}, [])
return { hasAccount }
}