about summary refs log tree commit diff
path: root/src/lib/hooks/useEmail.ts
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2024-11-23 16:20:24 -0800
committerGitHub <noreply@github.com>2024-11-23 16:20:24 -0800
commit32bf8122e8c8a0fbadd53b8a015cfbc9014519a2 (patch)
tree55bd24596e6fadadbf4326b26e3d14e418c5c7bb /src/lib/hooks/useEmail.ts
parent523d1f01a51c0e85e49916fb42b204f7004ffac1 (diff)
parentb4d07c4112b9a62b5380948051aa4a7fd391a2d4 (diff)
downloadvoidsky-32bf8122e8c8a0fbadd53b8a015cfbc9014519a2.tar.zst
Merge branch 'main' into main
Diffstat (limited to 'src/lib/hooks/useEmail.ts')
-rw-r--r--src/lib/hooks/useEmail.ts32
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}
+}