diff options
Diffstat (limited to 'src/lib/hooks/useEmail.ts')
-rw-r--r-- | src/lib/hooks/useEmail.ts | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/lib/hooks/useEmail.ts b/src/lib/hooks/useEmail.ts new file mode 100644 index 000000000..a8f4c6ad2 --- /dev/null +++ b/src/lib/hooks/useEmail.ts @@ -0,0 +1,32 @@ +import {useServiceConfigQuery} from '#/state/queries/email-verification-required' +import {useProfileQuery} from '#/state/queries/profile' +import {useSession} from '#/state/session' +import {BSKY_SERVICE} from '../constants' +import {getHostnameFromUrl} from '../strings/url-helpers' + +export function useEmail() { + const {currentAccount} = useSession() + + const {data: serviceConfig} = useServiceConfigQuery() + const {data: profile} = useProfileQuery({did: currentAccount?.did}) + + const checkEmailConfirmed = !!serviceConfig?.checkEmailConfirmed + + // Date set for 11 AM PST on the 18th of November + const isNewEnough = + !!profile?.createdAt && + Date.parse(profile.createdAt) >= Date.parse('2024-11-18T19:00:00.000Z') + + const isSelfHost = + currentAccount && + getHostnameFromUrl(currentAccount.service) !== + getHostnameFromUrl(BSKY_SERVICE) + + const needsEmailVerification = + !isSelfHost && + checkEmailConfirmed && + !currentAccount?.emailConfirmed && + isNewEnough + + return {needsEmailVerification} +} |