Skip to content

Commit

Permalink
worked on auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen-Gordon committed Mar 21, 2024
1 parent 8804299 commit 0f1b92d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 23 deletions.
11 changes: 6 additions & 5 deletions src/app/authenticated-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@
import { usePrivy } from '@privy-io/react-auth'
import { useEffect } from 'react'
import { useRouter } from 'next/navigation'
import { usePrivySmartAccount } from '@zerodev/privy'

interface Props {
children: React.ReactNode
}

const AuthenticatedPage = ({ children }: Props) => {
const router = useRouter()
const { ready, authenticated } = usePrivy()
const { zeroDevReady, authenticated } = usePrivySmartAccount()

useEffect(() => {
if (ready && !authenticated) router.push('/')
}, [ready, authenticated, router])
if (zeroDevReady && !authenticated) router.push('/home')
}, [zeroDevReady, authenticated, router])

return (
<div>

<main className='mx-auto max-w-screen-md pt-20 pb-16 px-safe sm:pb-0'>
<div className='p-6'>{children}</div>
<main className=''>
<div className=''>{children}</div>
</main>

</div>
Expand Down
6 changes: 2 additions & 4 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ export default function RootLayout({

const pathname = usePathname();

const { authenticated, zeroDevReady } = usePrivySmartAccount();


useEffect(() => {})

Expand All @@ -75,7 +73,7 @@ export default function RootLayout({
}
}, []); */

useEffect(() => {
/* useEffect(() => {
if (authenticated && zeroDevReady) {
Expand All @@ -86,7 +84,7 @@ export default function RootLayout({
} else {
router.push('/login');
}
}, [authenticated, zeroDevReady]);
}, [authenticated, zeroDevReady]); */


return (
Expand Down
23 changes: 11 additions & 12 deletions src/app/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,34 @@ import Link from 'next/link';
const Page = () => {
const [isInstalled, setIsInstalled] = useState(false);
const [installationPrompt, setInstallationPrompt] = useState<any>();

// router
const router = useRouter();

// privy
const { ready, authenticated, login, zeroDevReady, user } =
usePrivySmartAccount();

// redux
const dispatch = useDispatch();

useEffect(() => {
// Helps you prompt your users to install your PWA
// See https://web.dev/learn/pwa/installation-prompt/
// iOS Safari does not have this event, so you will have
// to prompt users to add the PWA via your own UI (e.g. a
// pop-up modal)
/* useEffect(() => {
window.addEventListener('beforeinstallprompt', (e) => {
e.preventDefault();
setIsInstalled(false);
setInstallationPrompt(e);
});
}, []);
}, []); */

useEffect(() => {
// Detect if the PWA is installed
// https://web.dev/learn/pwa/detection/#detecting-the-transfer
/* useEffect(() => {
window.addEventListener('DOMContentLoaded', () => {
if (window.matchMedia('(display-mode: standalone)').matches) {
setIsInstalled(true);
}
});
});
}); */
useEffect(() => {
if (zeroDevReady && authenticated ) {
// set user address
Expand All @@ -53,7 +52,7 @@ const Page = () => {
// route home
router.push('/home');
}
}, [authenticated, zeroDevReady, user]);
}, [authenticated, zeroDevReady]);


return (
Expand Down
19 changes: 17 additions & 2 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,25 @@ import Link from 'next/link';
export default function HomePage() {
const router = useRouter();


const { zeroDevReady, authenticated } = usePrivySmartAccount();

const { isMobile, userAgentString, userAgent, isStandalone } =
useUserAgent();


useEffect(() => {
if (zeroDevReady && authenticated) router.push('/home');
}, [zeroDevReady, authenticated, router]);

useEffect(() => {
if (isStandalone) {
router.push('/login');
}
}, [isStandalone])

const [welcomeMessage, setWelcomeMessage] =
useState<string>('Checking device...');
const { isMobile, userAgentString, userAgent, isStandalone } = useUserAgent();

useEffect(() => {
const welcomeMessage = isMobile
Expand All @@ -33,7 +48,7 @@ export default function HomePage() {
<AddToHomeScreen />

<Link href='/home'>Home</Link>

<Link href='/home'>login</Link>
</main>
);
}

0 comments on commit 0f1b92d

Please sign in to comment.