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-next-auth

UseNextAuth

guarahooks/use-next-auth
FreeHook

Enhanced wrapper for NextAuth.js session management.

Install it

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

Source

registry/hooks/use-next-auth.tsxguarahooks.com/r/use-next-auth.json
1'use client';
2
3import { useCallback, useEffect, useRef } from 'react';
4
5import type { Session } from 'next-auth';
6import { signIn, signOut, useSession } from 'next-auth/react';
7
8export interface UseNextAuthReturn<T extends Session = Session> {
9 session: T | null;
10 status: 'authenticated' | 'unauthenticated' | 'loading';
11 isAuthenticated: boolean;
12 signIn: typeof signIn;
13 signOut: typeof signOut;
14 refresh: () => Promise<void>;
15}
16
17export interface UseNextAuthOptions<T extends Session = Session> {
18 onSessionChange?: (
19 session: T | null,
20 status: 'authenticated' | 'unauthenticated' | 'loading',
21 ) => void;
22 /** Interval in milliseconds to refresh the session automatically */
23 refreshInterval?: number;
24 onError?: (error: Error) => void;
25}
26
27/**
28 * Enhanced hook for NextAuth.js session management with additional features
29 *
30 * @template T - Custom session interface extending NextAuth Session
31 * @param options - Configuration options for the hook
32 * @returns Enhanced session object with additional utilities
33 */
34export function useNextAuth<T extends Session = Session>(
35 options: UseNextAuthOptions<T> = {},
36): UseNextAuthReturn<T> {
37 const { onSessionChange, refreshInterval, onError } = options;
38 const { data, status, update } = useSession();
39 const previousRef = useRef<T | null>(null);
40
41 const safeSignIn = useCallback<typeof signIn>(
42 async (...args) => {
43 try {
44 return await signIn(...args);
45 } catch (err) {
46 onError?.(err as Error);
47 throw err;
48 }
49 },
50 [onError],
51 );
52
53 const safeSignOut = useCallback<typeof signOut>(
54 async (...args) => {
55 try {
56 return await signOut(...args);
57 } catch (err) {
58 onError?.(err as Error);
59 throw err;
60 }
61 },
62 [onError],
63 );
64
65 const refresh = useCallback(async () => {
66 await update();
67 }, [update]);
68
69 // Auto-refresh session at specified intervals
70 useEffect(() => {
71 if (!refreshInterval) return;
72 const id = setInterval(refresh, refreshInterval);
73 return () => clearInterval(id);
74 }, [refreshInterval, refresh]);
75
76 // Session change detection and callbacks
77 useEffect(() => {
78 if (onSessionChange && previousRef.current !== data) {
79 onSessionChange(data as T | null, status);
80 previousRef.current = data as T | null;
81 }
82 }, [data, status, onSessionChange]);
83
84 // Debug logging in development mode
85 useEffect(() => {
86 if (process.env.NODE_ENV === 'development') {
87// … truncated

Files it writes

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

Facts

Registry
guarahooks
Type
registry:hook
Access
Free
Files written
1
Licence
MIT
In the index
at or before 2026-08-10
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
UseBetterAuthuse-better-authguarahooksHooksFreeno deps
UseClickOutsideuse-click-outsideguarahooksHooksFreeno deps
UseConfirmuse-confirmguarahooksHooksFreeno deps
UseCookieuse-cookieguarahooksHooksFreeno 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