Skip to main content
Glama
AuthenticationBarrierClient.tsx1.67 kB
'use client'; import { Loader } from '@intlayer/design-system'; import { useSession } from '@intlayer/design-system/hooks'; import { usePathname, useRouter } from 'next/navigation'; import { type FC, useEffect } from 'react'; import { PagesRoutes } from '@/Routes'; import { type AuthenticationBarrierProps, accessValidation, } from './accessValidation'; type AuthenticationBarrierPropsClient = Omit< AuthenticationBarrierProps, 'sessionToken' | 'redirectionFunction' > & { redirectionRoute?: PagesRoutes | string; originUrl?: string; }; export const AuthenticationBarrierClient: FC< AuthenticationBarrierPropsClient > = ({ children, redirectionRoute = PagesRoutes.Home, session: sessionProp, accessRule, isEnabled, originUrl, }) => { const router = useRouter(); const pathname = usePathname(); const { session: sessionClient } = useSession(sessionProp); const isLoading = sessionClient === undefined && sessionProp === undefined; useEffect(() => { // Do nothing if we have explicitly disabled it (the server has already made a decision) if (isEnabled === false) return; if (typeof sessionClient === 'undefined') return; const samePath = typeof window !== 'undefined' && (redirectionRoute === pathname || redirectionRoute === originUrl); if (samePath) return; accessValidation( accessRule, sessionClient, (url) => router.replace(url), redirectionRoute, isEnabled ); }, [ accessRule, redirectionRoute, sessionClient, isEnabled, pathname, originUrl, router, ]); return <Loader isLoading={isLoading}>{children}</Loader>; };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/aymericzip/intlayer'

If you have feedback or need assistance with the MCP directory API, please join our Discord server