diff --git a/apps/web/src/controllers/AppNoPageAccess.tsx b/apps/web/src/controllers/AppNoPageAccess.tsx index eb99d0ef9..789095106 100644 --- a/apps/web/src/controllers/AppNoPageAccess.tsx +++ b/apps/web/src/controllers/AppNoPageAccess.tsx @@ -1,29 +1,58 @@ +'use client'; + import Link from 'next/link'; -import React from 'react'; +import React, { useMemo } from 'react'; import { BusterLogo } from '@/assets/svg/BusterLogo'; import { Button } from '@/components/ui/buttons'; import { Title } from '@/components/ui/typography'; +import { useSupabaseContext } from '@/context/Supabase'; import { BusterRoutes, createBusterRoute } from '@/routes'; export const AppNoPageAccess: React.FC<{ assetId: string; }> = React.memo(({ assetId }) => { + const isAnonymousUser = useSupabaseContext((x) => x.isAnonymousUser); + + const { buttonText, linkUrl } = useMemo(() => { + const isEmbedPage = typeof window !== 'undefined' && window.location.pathname.startsWith('/embed'); + + const shouldShowLogin = isAnonymousUser || isEmbedPage; + + if (shouldShowLogin) { + const currentUrl = typeof window !== 'undefined' + ? `${window.location.pathname}${window.location.search}` + : ''; + + return { + buttonText: 'Login', + linkUrl: createBusterRoute({ + route: BusterRoutes.AUTH_LOGIN, + next: encodeURIComponent(currentUrl) + }) + }; + } + + return { + buttonText: 'Go home', + linkUrl: createBusterRoute({ + route: BusterRoutes.APP_HOME + }) + }; + }, [isAnonymousUser]); + return (