20
components/hooks/useHasAccount.ts
Normal file
20
components/hooks/useHasAccount.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
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 }
|
||||
}
|
||||
@@ -10,7 +10,6 @@ export default async function fetcher<JSON = any>(
|
||||
}
|
||||
|
||||
export type Session = {
|
||||
isSignedIn: boolean
|
||||
csrfToken?: string
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import { useVersion } from 'components/hooks/useVersion'
|
||||
|
||||
import { Link } from 'components/Link'
|
||||
import { useMainContext } from 'components/context/MainContext'
|
||||
import { useSession } from 'components/hooks/useSession'
|
||||
import { useHasAccount } from 'components/hooks/useHasAccount'
|
||||
import { LanguagePicker } from './LanguagePicker'
|
||||
import { HeaderNotifications } from 'components/page-header/HeaderNotifications'
|
||||
import { ProductPicker } from 'components/page-header/ProductPicker'
|
||||
@@ -26,11 +26,10 @@ export const Header = () => {
|
||||
)
|
||||
const [scroll, setScroll] = useState(false)
|
||||
|
||||
const { session } = useSession()
|
||||
const { hasAccount } = useHasAccount()
|
||||
|
||||
const signupCTAVisible =
|
||||
session &&
|
||||
!session.isSignedIn &&
|
||||
hasAccount === false && // don't show if `null`
|
||||
(currentVersion === 'free-pro-team@latest' || currentVersion === 'enterprise-cloud@latest')
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -6,10 +6,7 @@ const noCacheControl = cacheControlFactory(0)
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
noCacheControl(res)
|
||||
res.json({
|
||||
isSignedIn: Boolean(req.cookies?.dotcom_user),
|
||||
csrfToken: req.csrfToken?.() || '',
|
||||
})
|
||||
res.json({ csrfToken: req.csrfToken?.() || '' })
|
||||
})
|
||||
|
||||
export default router
|
||||
|
||||
Reference in New Issue
Block a user