UNPKG

@inertiapixel/nextjs-auth

Version:

Authentication system for Next.js. Supports credentials and social login, JWT token management, and lifecycle hooks — designed to integrate with nodejs-auth for full-stack MERN apps.

24 lines (23 loc) 813 B
'use client'; import { usePathname, useSearchParams } from 'next/navigation'; import { useEffect, useRef, useMemo } from 'react'; export function useNavigation() { const pathname = usePathname(); const searchParams = useSearchParams(); const previousPathRef = useRef(null); const fullPath = useMemo(() => { const query = searchParams.toString(); return query ? `${pathname}?${query}` : pathname; }, [pathname, searchParams]); useEffect(() => { if (typeof window !== 'undefined') { previousPathRef.current = sessionStorage.getItem('previousUrl'); sessionStorage.setItem('previousUrl', fullPath); } }, [fullPath]); return { current: pathname, full: fullPath, previous: previousPathRef.current, }; }