mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import {useServiceConfigQuery} from '#/state/queries/email-verification-required'
2import {useProfileQuery} from '#/state/queries/profile'
3import {useSession} from '#/state/session'
4import {BSKY_SERVICE} from '../constants'
5import {getHostnameFromUrl} from '../strings/url-helpers'
6
7export function useEmail() {
8 const {currentAccount} = useSession()
9
10 const {data: serviceConfig} = useServiceConfigQuery()
11 const {data: profile} = useProfileQuery({did: currentAccount?.did})
12
13 const checkEmailConfirmed = !!serviceConfig?.checkEmailConfirmed
14
15 // Date set for 11 AM PST on the 18th of November
16 const isNewEnough =
17 !!profile?.createdAt &&
18 Date.parse(profile.createdAt) >= Date.parse('2024-11-18T19:00:00.000Z')
19
20 const isSelfHost =
21 currentAccount &&
22 getHostnameFromUrl(currentAccount.service) !==
23 getHostnameFromUrl(BSKY_SERVICE)
24
25 const needsEmailVerification =
26 !isSelfHost &&
27 checkEmailConfirmed &&
28 !currentAccount?.emailConfirmed &&
29 isNewEnough
30
31 return {needsEmailVerification}
32}