@equinor/mad-core
Version:
Core library for the Mobile App Delivery team
44 lines (41 loc) • 1.26 kB
JavaScript
import {
useCoreStackNavigation
} from "./chunk-BIMOM43W.js";
import {
useDemoMode
} from "./chunk-UZ6YMQV2.js";
import {
getConfig
} from "./chunk-GEEFQMRN.js";
import {
CoreRoutes
} from "./chunk-UKAZW3CQ.js";
import {
__async
} from "./chunk-CWMXXUWU.js";
// src/components/screens/settings/useSignOut.ts
import { useCallback } from "react";
import { ExpoAuthSession, signOut } from "@equinor/mad-auth";
import { alert } from "@equinor/mad-components";
var useSignOut = () => {
const navigation = useCoreStackNavigation();
const demoMode = useDemoMode();
const signOutFn = useCallback(() => __async(void 0, null, function* () {
var _a;
try {
const result = ((_a = getConfig().experimental) == null ? void 0 : _a.useExpoAuthSession) ? ExpoAuthSession.signOut() : yield signOut();
if (!demoMode.isEnabled && !result) throw new Error("Unable to sign out");
demoMode.disableDemoMode();
navigation.navigate(CoreRoutes.LOGIN);
} catch (_) {
alert("Error", "Unable to sign out", [
{ text: "Try again", isPreferred: true, onPress: () => void signOutFn() },
{ text: "Cancel", onPress: () => void 0 }
]);
}
}), [navigation, demoMode]);
return signOutFn;
};
export {
useSignOut
};