Merged authentication context with state and action methods.
export function useAuth(): AuthContextType {
const stateContext = useContext(AuthStateContext);
const actionsContext = useContext(AuthActionsContext);
const mergedContext = useMemo(() => {
if (stateContext !== undefined && actionsContext !== undefined) {
return {
...stateContext,
...actionsContext,
} satisfies AuthContextType;
}
return undefined;
}, [actionsContext, stateContext]);
if (mergedContext === undefined) {
throw new Error("useAuth must be used within an AuthProvider");
}
return mergedContext;
}
Accesses the complete authentication context combining state and actions. Merges both contexts for convenient single-hook access to auth data and methods.