Add 'apps/mobile/' from commit '5fa30f365f21531094cd4d2045042bb4f1370ac3'
git-subtree-dir: apps/mobile git-subtree-mainline:86f8987dffgit-subtree-split:5fa30f365f
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import { router } from "expo-router";
|
||||
import { Alert } from "react-native";
|
||||
import type { createAuthClient } from "better-auth/react";
|
||||
|
||||
import type { RemoveAccountResult } from "@/contexts/AccountsContext";
|
||||
import { performAuthReset } from "@/lib/auth-session";
|
||||
|
||||
type AuthClient = ReturnType<typeof createAuthClient>;
|
||||
|
||||
type FinishAccountRemovalInput = {
|
||||
result: RemoveAccountResult;
|
||||
authClient: AuthClient;
|
||||
clearActiveAccount: () => Promise<void>;
|
||||
activeAccountId: string | null;
|
||||
};
|
||||
|
||||
/** Navigate to sign-in when the last saved account was removed. */
|
||||
export async function finishAccountRemoval({
|
||||
result,
|
||||
authClient,
|
||||
clearActiveAccount,
|
||||
activeAccountId,
|
||||
}: FinishAccountRemovalInput): Promise<void> {
|
||||
if (result.remainingCount > 0) return;
|
||||
|
||||
await performAuthReset({
|
||||
authClient,
|
||||
clearActiveAccount,
|
||||
activeAccountId,
|
||||
});
|
||||
router.replace("/(auth)/sign-in");
|
||||
}
|
||||
|
||||
export function confirmRemoveAccount(
|
||||
label: string,
|
||||
onRemove: () => Promise<RemoveAccountResult>,
|
||||
onFinished: (result: RemoveAccountResult) => Promise<void>,
|
||||
) {
|
||||
Alert.alert("Remove account", `Remove ${label} from this device?`, [
|
||||
{ text: "Cancel", style: "cancel" },
|
||||
{
|
||||
text: "Remove",
|
||||
style: "destructive",
|
||||
onPress: () => {
|
||||
void (async () => {
|
||||
const result = await onRemove();
|
||||
await onFinished(result);
|
||||
})();
|
||||
},
|
||||
},
|
||||
]);
|
||||
}
|
||||
Reference in New Issue
Block a user