diff options
Diffstat (limited to 'src/state/session')
-rw-r--r-- | src/state/session/index.tsx | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/state/session/index.tsx b/src/state/session/index.tsx index 97bd6e976..d7541295b 100644 --- a/src/state/session/index.tsx +++ b/src/state/session/index.tsx @@ -8,6 +8,7 @@ import * as persisted from '#/state/persisted' import {PUBLIC_BSKY_AGENT} from '#/state/queries' import {IS_PROD} from '#/lib/constants' import {emitSessionLoaded, emitSessionDropped} from '../events' +import {useLoggedOutViewControls} from '#/state/shell/logged-out' let __globalAgent: BskyAgent = PUBLIC_BSKY_AGENT @@ -515,3 +516,19 @@ export function useSession() { export function useSessionApi() { return React.useContext(ApiContext) } + +export function useRequireAuth() { + const {hasSession} = useSession() + const {setShowLoggedOut} = useLoggedOutViewControls() + + return React.useCallback( + (fn: () => void) => { + if (hasSession) { + fn() + } else { + setShowLoggedOut(true) + } + }, + [hasSession, setShowLoggedOut], + ) +} |