diff --git a/apps/mobile/src/lib/auth.ts b/apps/mobile/src/lib/auth.ts
index 600f5d880..66931ef1a 100644
--- a/apps/mobile/src/lib/auth.ts
+++ b/apps/mobile/src/lib/auth.ts
@@ -6,10 +6,13 @@ import { createMobileAPIHeaders } from "@follow/utils/headers"
import { useQuery } from "@tanstack/react-query"
import { createAuthClient } from "better-auth/react"
import { nativeApplicationVersion } from "expo-application"
+import * as FileSystem from "expo-file-system"
import * as SecureStore from "expo-secure-store"
import { Platform } from "react-native"
import DeviceInfo from "react-native-device-info"
+import { getDbPath } from "@/src/database"
+
import { getClientId, getSessionId } from "./client-session"
import { getUserAgent } from "./native/user-agent"
import { getEnvProfile, proxyEnv } from "./proxy-env"
@@ -82,7 +85,6 @@ export const {
oneTimeToken,
sendVerificationEmail,
signIn,
- signOut,
signUp,
twoFactor,
unlinkAccount,
@@ -117,3 +119,20 @@ export function isAuthCodeValid(authCode: string) {
authCode.length === 6 && !Array.from(authCode).some((c) => Number.isNaN(Number.parseInt(c)))
)
}
+
+export const signOut = async () => {
+ await authClient.signOut()
+ const dbPath = getDbPath()
+ await FileSystem.deleteAsync(dbPath)
+ await expo.reloadAppAsync("User sign out")
+}
+
+export const deleteUser = async ({ TOTPCode }: { TOTPCode?: string }) => {
+ if (!TOTPCode) {
+ return
+ }
+ await authClient.deleteUserCustom({
+ TOTPCode,
+ })
+ await signOut()
+}
diff --git a/apps/mobile/src/modules/dialogs/ConfirmTOTPCodeDialog.tsx b/apps/mobile/src/modules/dialogs/ConfirmTOTPCodeDialog.tsx
new file mode 100644
index 000000000..fa952deae
--- /dev/null
+++ b/apps/mobile/src/modules/dialogs/ConfirmTOTPCodeDialog.tsx
@@ -0,0 +1,41 @@
+import { Text, View } from "react-native"
+import { useColor } from "react-native-uikit-colors"
+
+import { PlainTextField } from "@/src/components/ui/form/TextField"
+import { Key2CuteReIcon } from "@/src/icons/key_2_cute_re"
+import type { DialogComponent } from "@/src/lib/dialog"
+import { Dialog } from "@/src/lib/dialog"
+
+export const ConfirmTOTPCodeDialog: DialogComponent<{
+ totpCode: string
+}> = ({ ctx }) => {
+ const label = useColor("label")
+ const { bizOnConfirm } = Dialog.useDialogContext()!
+ return (
+
+
+
+ Enter your TOTP code to continue
+
+ (ctx.totpCode = text)}
+ returnKeyType="done"
+ onSubmitEditing={() => {
+ bizOnConfirm?.()
+ }}
+ />
+
+ )
+}
+
+ConfirmTOTPCodeDialog.id = "confirm-password-dialog"
+ConfirmTOTPCodeDialog.confirmText = "Confirm"
+ConfirmTOTPCodeDialog.cancelText = "Cancel"
+ConfirmTOTPCodeDialog.onConfirm = (ctx) => {
+ ctx.dismiss()
+}
diff --git a/apps/mobile/src/modules/settings/SettingsList.tsx b/apps/mobile/src/modules/settings/SettingsList.tsx
index 2dbfcc864..f44cc0cfa 100644
--- a/apps/mobile/src/modules/settings/SettingsList.tsx
+++ b/apps/mobile/src/modules/settings/SettingsList.tsx
@@ -1,7 +1,6 @@
import { UserRole } from "@follow/constants"
import type { ServerConfigs } from "@follow/models/types"
import { useUserRole, useWhoami } from "@follow/store/user/hooks"
-import * as FileSystem from "expo-file-system"
import type { ParseKeys } from "i18next"
import type { FC } from "react"
import { Fragment, useMemo } from "react"
@@ -14,7 +13,6 @@ import {
GroupedInsetListNavigationLink,
GroupedInsetListNavigationLinkIcon,
} from "@/src/components/ui/grouped/GroupedList"
-import { getDbPath } from "@/src/database"
import { CertificateCuteFiIcon } from "@/src/icons/certificate_cute_fi"
import { DatabaseIcon } from "@/src/icons/database"
import { ExitCuteFiIcon } from "@/src/icons/exit_cute_fi"
@@ -180,11 +178,7 @@ const ActionGroupNavigationLinks: GroupNavigationLink[] = [
text: "Sign out",
style: "destructive",
onPress: async () => {
- // sign out
await signOut()
- const dbPath = getDbPath()
- await FileSystem.deleteAsync(dbPath)
- await expo.reloadAppAsync("User sign out")
},
},
])
diff --git a/apps/mobile/src/modules/settings/routes/Account.tsx b/apps/mobile/src/modules/settings/routes/Account.tsx
index b307da066..8e396dacb 100644
--- a/apps/mobile/src/modules/settings/routes/Account.tsx
+++ b/apps/mobile/src/modules/settings/routes/Account.tsx
@@ -1,7 +1,6 @@
import { useWhoami } from "@follow/store/user/hooks"
import { userSyncService } from "@follow/store/user/store"
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
-import * as FileSystem from "expo-file-system"
import type { FC } from "react"
import { useMemo } from "react"
import { useTranslation } from "react-i18next"
@@ -20,17 +19,16 @@ import {
GroupedPlainButtonCell,
} from "@/src/components/ui/grouped/GroupedList"
import { PlatformActivityIndicator } from "@/src/components/ui/loading/PlatformActivityIndicator"
-import { getDbPath } from "@/src/database"
import { AppleCuteFiIcon } from "@/src/icons/apple_cute_fi"
import { GithubCuteFiIcon } from "@/src/icons/github_cute_fi"
import { GoogleCuteFiIcon } from "@/src/icons/google_cute_fi"
import type { AuthProvider } from "@/src/lib/auth"
import {
+ deleteUser,
forgetPassword,
getAccountInfo,
getProviders,
linkSocial,
- signOut,
unlinkAccount,
} from "@/src/lib/auth"
import { Dialog } from "@/src/lib/dialog"
@@ -40,6 +38,7 @@ import { useNavigation } from "@/src/lib/navigation/hooks"
import { toast } from "@/src/lib/toast"
import { ConfirmPasswordDialog } from "../../dialogs/ConfirmPasswordDialog"
+import { ConfirmTOTPCodeDialog } from "../../dialogs/ConfirmTOTPCodeDialog"
import { TwoFASetting } from "./2FASetting"
import { ResetPassword } from "./ResetPassword"
@@ -76,33 +75,7 @@ export const AccountScreen = () => {
Header={}
>
-
-
- {/* Danger Zone */}
-
-
-
- {
- Alert.alert("Delete account", "Are you sure you want to delete your account?", [
- { text: "Cancel", style: "cancel" },
- {
- text: "Delete",
- style: "destructive",
- onPress: async () => {
- await signOut()
- const dbPath = getDbPath()
- await FileSystem.deleteAsync(dbPath)
- await expo.reloadAppAsync("User sign out")
- },
- },
- ])
- }}
- />
-
)
}
@@ -317,6 +290,34 @@ const SecuritySection = () => {
})
}}
/>
+ {
+ Alert.alert(
+ "Delete account",
+ "Are you sure you want to delete your account? \nThis action is irreversible and may take up to two days to take effect.",
+ [
+ { text: "Cancel", style: "cancel" },
+ {
+ text: "Delete",
+ style: "destructive",
+ onPress: async () => {
+ // await signOut()
+ Dialog.show(ConfirmTOTPCodeDialog, {
+ override: {
+ async onConfirm(ctx) {
+ ctx.dismiss()
+ await deleteUser({ TOTPCode: ctx.totpCode })
+ },
+ },
+ })
+ },
+ },
+ ],
+ )
+ }}
+ />
>
)