BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/guarahooks/use-better-auth

UseBetterAuth

guarahooks/use-better-auth
FreeHook

Flexible authentication hook.

Install it

npx shadcn@latest add https://guarahooks.com/r/use-better-auth.json

Source

registry/hooks/use-better-auth.tsxguarahooks.com/r/use-better-auth.json · first 6 KB
1'use client';
2
3import { useCallback, useEffect, useState } from 'react';
4
5export interface StorageLike {
6 getItem(key: string): string | null;
7 setItem(key: string, value: string): void;
8 removeItem(key: string): void;
9}
10
11export interface BetterAuthResponse<TUser> {
12 token: string;
13 user: TUser;
14}
15
16export interface DefaultCredentials
17 extends Record<string, string | number | boolean> {
18 email: string;
19 password: string;
20}
21
22export interface UseBetterAuthReturn<
23 TUser,
24 TCredentials extends Record<string, string | number | boolean>,
25> {
26 token: string | null;
27 user: TUser | null;
28 loading: boolean;
29 error: Error | null;
30 isAuthenticated: boolean;
31 login: (credentials: TCredentials) => Promise<void>;
32 logout: () => void;
33 refresh: () => Promise<void>;
34 updateUser: (user: TUser, token?: string) => void;
35 clearError: () => void;
36}
37
38export interface UseBetterAuthOptions<
39 TUser,
40 TCredentials extends Record<string, string | number | boolean>,
41> {
42 /** Storage key prefix for storing authentication data. Defaults to 'better-auth' */
43 storageKey?: string;
44 /** Custom storage implementation. Defaults to localStorage */
45 storage?: StorageLike;
46 /** Login endpoint URL. Defaults to '/api/login' */
47 loginUrl?: string;
48 /** Token refresh endpoint URL */
49 refreshUrl?: string;
50 /** Logout endpoint URL */
51 logoutUrl?: string;
52 /** Auto-refresh interval in milliseconds */
53 refreshInterval?: number;
54 /** Callback fired when authentication state changes */
55 onAuthChange?: (token: string | null, user: TUser | null) => void;
56 /** Custom fetcher function for authentication requests */
57 fetcher?: (
58 credentials: TCredentials,
59 url: string,
60 ) => Promise<BetterAuthResponse<TUser>>;
61}
62
63/**
64 * A flexible authentication hook that provides login, logout, token refresh, and user management.
65 *
66 * Features:
67 * - Customizable storage (localStorage, sessionStorage, or custom implementation)
68 * - Automatic token refresh with configurable intervals
69 * - SSR-safe with proper hydration handling
70 * - Type-safe with generic user and credentials types
71 * - Custom fetcher support for different API implementations
72 * - Cross-tab synchronization through storage events
73 * - Error handling with clear error states
74 *
75 * @example
76 * ```tsx
77 * // Basic usage
78 * const auth = useBetterAuth<User>({
79 * loginUrl: '/api/auth/login',
80 * refreshUrl: '/api/auth/refresh',
81 * });
82 *
83 * // Login
84// … truncated

Files it writes

  • registry/hooks/use-better-auth.tsx

Facts

Registry
guarahooks
Type
registry:hook
Access
Free
Files written
1
Licence
MIT
In the index
at or before 2026-08-11
Last confirmed
today

Go to the source

guarahooks.com h3rmel/guarahooks on GitHub Raw registry item This item as JSON

More from guarahooks

All 100 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
UseAbortControlleruse-abort-controllerguarahooksHooksFreeno deps
UseArrayStateuse-array-stateguarahooksHooksFreeno deps
UseAxiosuse-axiosguarahooksHooksFreeno deps
UseBatteryStatususe-battery-statusguarahooksHooksFreeno deps
UseClickOutsideuse-click-outsideguarahooksHooksFreeno deps
UseConfirmuse-confirmguarahooksHooksFreeno deps
UseCookieuse-cookieguarahooksHooksFreeno deps
UseCopyToClipboarduse-copy-to-clipboardguarahooksHooksFreeno deps

Also from Kynth Studios

Built for the same person as BlockDex

SkillWorks

Claude Code skills and plugins, scored

skillworks.kynth.studio

RuleStack

AGENTS.md gallery and agent-config comparison

rulestack.kynth.studio

ToolDrift

What the AI coding tools changed last night

tooldrift.kynth.studio

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex