diff --git a/components/hooks/useHasAccount.ts b/components/hooks/useHasAccount.ts new file mode 100644 index 0000000000..6ed6635315 --- /dev/null +++ b/components/hooks/useHasAccount.ts @@ -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(null) + + useEffect(() => { + const cookieValue = Cookies.get('color_mode') + setHasAccount(Boolean(cookieValue)) + }, []) + + return { hasAccount } +} diff --git a/components/hooks/useSession.ts b/components/hooks/useSession.ts index 1ea66391d8..38d17de698 100644 --- a/components/hooks/useSession.ts +++ b/components/hooks/useSession.ts @@ -10,7 +10,6 @@ export default async function fetcher( } export type Session = { - isSignedIn: boolean csrfToken?: string } diff --git a/components/page-header/Header.tsx b/components/page-header/Header.tsx index 9e2f848791..09b8c1c0f3 100644 --- a/components/page-header/Header.tsx +++ b/components/page-header/Header.tsx @@ -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(() => { diff --git a/middleware/api/session.js b/middleware/api/session.js index 057b69c545..4d83e01c26 100644 --- a/middleware/api/session.js +++ b/middleware/api/session.js @@ -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