aboutsummaryrefslogtreecommitdiffstats
path: root/apps/mobile/lib/session.ts
blob: 071748b9d43332a90387f7dd8ce9c9171081441b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { useCallback, useMemo } from "react";

import useAppSettings from "./settings";

export function useSession() {
  const { settings, isLoading, setSettings } = useAppSettings();
  const isLoggedIn = useMemo(() => {
    return isLoading ? undefined : !!settings.apiKey;
  }, [isLoading, settings]);

  const logout = useCallback(() => {
    setSettings({ ...settings, apiKey: undefined });
  }, [settings, setSettings]);

  return {
    isLoggedIn,
    isLoading,
    logout,
  };
}