Move auth and timezone hooks into dedicated hook files

This commit is contained in:
2026-04-18 20:35:28 +02:00
parent d9550ae4aa
commit fba7675eb8
8 changed files with 40 additions and 49 deletions

View File

@@ -0,0 +1,15 @@
import { useContext } from "react";
import { AuthContext, type AuthContextValue } from "../providers/AuthProvider";
/**
* Access authentication state and actions from a mounted AuthProvider.
*
* @throws {Error} When called outside of `<AuthProvider>`.
*/
export function useAuth(): AuthContextValue {
const ctx = useContext(AuthContext);
if (ctx === null) {
throw new Error("useAuth must be used within <AuthProvider>.");
}
return ctx;
}

View File

@@ -0,0 +1,15 @@
import { useContext } from "react";
import { TimezoneContext } from "../providers/TimezoneProvider";
/**
* Return the configured IANA timezone from the mounted TimezoneProvider.
*
* @throws {Error} When called outside of `<TimezoneProvider>`.
*/
export function useTimezone(): string {
const context = useContext(TimezoneContext);
if (context === undefined) {
throw new Error("useTimezone must be used within <TimezoneProvider>.");
}
return context.timezone;
}