-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
85 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { useAuthorized } from 'h/useAuthorized' | ||
import type { FC } from 'react' | ||
import { Navigate, Outlet } from 'react-router-dom' | ||
|
||
export const ProtectedRoute: FC = () => { | ||
const { auth, loading } = useAuthorized() | ||
|
||
if (loading) | ||
return null | ||
|
||
if (auth === false) { | ||
alert('Nice try! But we need to verify your age first.') | ||
return <Navigate replace to='/' /> | ||
} | ||
|
||
return <Outlet /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,18 @@ | ||
import { useAuthorized } from 'h/useAuthorized' | ||
|
||
export function X() { | ||
useAuthorized() | ||
return ( | ||
<div className='flex flex-col items-center justify-center'> | ||
<h1 className='text-3xl font-bold text-center text-violet'>Gallery</h1> | ||
<div className='w-full max-w-5xl'> | ||
{/* Adjust max-w-5xl as needed */} | ||
<div className='grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4 justify-items-center'> | ||
{[0, 1, 2].map((index) => ( | ||
<div key={index} className='bg-wisteria p-4 rounded-lg shadow-lg w-full max-w-xs'> | ||
{/* Adjust max-w-xs as needed */} | ||
<img | ||
src={`/dog${index}.avif`} | ||
alt={`Dog eating corndog AI generated drawing ${index + 1}`} | ||
className='w-full h-auto rounded object-cover' | ||
/> | ||
</div> | ||
))} | ||
</div> | ||
export const X = () => ( | ||
<div className='flex flex-col items-center justify-center'> | ||
<h1 className='text-3xl font-bold text-center text-violet'>Gallery</h1> | ||
<div className='w-full max-w-5xl'> | ||
<div className='grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4 justify-items-center'> | ||
{[0, 1, 2].map((index) => ( | ||
<div key={index} className='bg-wisteria p-4 rounded-lg shadow-lg w-full max-w-xs'> | ||
<img | ||
src={`/dog${index}.avif`} | ||
alt={`Dog eating corndog AI generated drawing ${index + 1}`} | ||
className='w-full h-auto rounded object-cover' | ||
/> | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
) | ||
} | ||
</div> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,22 @@ | ||
import { useStore } from 'h/useStore' | ||
import Cookies from 'js-cookie' | ||
import { config } from 'l/config' | ||
import { useEffect } from 'react' | ||
import { useNavigate } from 'react-router-dom' | ||
import { useEffect, useState } from 'react' | ||
|
||
export const useAuthorized = () => { | ||
const { setProof } = useStore() | ||
const navigate = useNavigate() | ||
|
||
useEffect(() => { | ||
if (Cookies.get(config.cookie.name) !== 'true') { | ||
// FIXME this renders twice | ||
alert('Nice try! But we need to verify your age first (try clicking the Login button)') | ||
navigate('/') | ||
} | ||
}, [navigate]) | ||
const { auth, setAuth, setProof } = useStore() | ||
const [loading, setLoading] = useState(true) | ||
|
||
const logout = () => { | ||
setAuth(false) | ||
setProof(null) | ||
Cookies.remove(config.cookie.name) | ||
} | ||
|
||
return { logout } | ||
useEffect(() => { | ||
setAuth(Cookies.get(config.cookie.name) === 'true') | ||
setLoading(false) | ||
}, [setAuth]) | ||
|
||
return { auth, loading, logout } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import { useStoreActions, useStoreState } from 'l/store' | ||
|
||
export const useStore = () => ({ | ||
auth: useStoreState(state => state.auth.data), | ||
proof: useStoreState(state => state.proof.data), | ||
setAuth: useStoreActions(actions => actions.auth.set), | ||
setProof: useStoreActions(actions => actions.proof.set), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters