Skip to content

Commit

Permalink
fix: show terms to unauthorized users (storacha#428)
Browse files Browse the repository at this point in the history
I had the AuthenticationEnsurer wrapping all pages, move that into
`index` where it belongs for now.
  • Loading branch information
travis authored Mar 23, 2023
1 parent dee09ba commit d7277fa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 49 deletions.
2 changes: 1 addition & 1 deletion packages/w3ui/examples/react/w3console/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createBrowserRouter, RouterProvider } from "react-router-dom";

import { Authenticator } from './components/Authenticator'
import { Authenticator } from '@w3ui/react-keyring'
import { W3APIProvider } from './components/W3API'

// thanks, https://dev.to/franciscomendes10866/file-based-routing-using-vite-and-react-router-3fdo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,4 @@ export function AuthenticationEnsurer ({
return <AuthenticationForm />
}

interface AuthenticatorProps {
children: JSX.Element | JSX.Element[]
className?: string
}

export function Authenticator ({
children,
className = ''
}: AuthenticatorProps): JSX.Element {
return (
<AuthCore as='div' className={className}>
<AuthenticationEnsurer>{children}</AuthenticationEnsurer>
</AuthCore>
)
}

/**
* Wrapping a component with this HoC ensures an identity exists.
*/
export function withIdentity<C extends React.JSXElementConstructor<P>, P> (
Component: C
) {
return (props: any) => (
<Authenticator>
<Component {...props} />
</Authenticator>
)
}
45 changes: 24 additions & 21 deletions packages/w3ui/examples/react/w3console/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Uploader } from '../components/Uploader'
import { UploadsList } from '../components/UploadsList'
import { SpaceFinder } from '../components/SpaceFinder'
import { SpaceCreatorForm, SpaceCreator } from '../components/SpaceCreator'
import { AuthenticationEnsurer } from '../components/Authenticator'

function SpaceRegistrar (): JSX.Element {
const [, { registerSpace }] = useKeyring()
Expand Down Expand Up @@ -227,28 +228,30 @@ export default function Home (): JSX.Element {
}

return (
<SpaceEnsurer>
<div className='flex min-h-full w-full'>
<nav className='flex-none w-64 bg-gray-900 text-white px-4 pb-4 border-r border-gray-800'>
<div className='flex flex-col justify-between min-h-full'>
<div class='flex-none'>
<SpaceSelector
selected={space}
setSelected={viewSpace}
spaces={spaces}
/>
<AuthenticationEnsurer>
<SpaceEnsurer>
<div className='flex min-h-full w-full'>
<nav className='flex-none w-64 bg-gray-900 text-white px-4 pb-4 border-r border-gray-800'>
<div className='flex flex-col justify-between min-h-full'>
<div class='flex-none'>
<SpaceSelector
selected={space}
setSelected={viewSpace}
spaces={spaces}
/>
</div>
<div>
<SpaceCreator className='mb-4' />
<Logo />
</div>
</div>
<div>
<SpaceCreator className='mb-4' />
<Logo />
</div>
</div>
</nav>
<main className='grow bg-gray-dark text-white p-4'>
<SpaceSection viewSpace={viewSpace} share={share} setShare={setShare} />
</main>
</div>
</SpaceEnsurer>
</nav>
<main className='grow bg-gray-dark text-white p-4'>
<SpaceSection viewSpace={viewSpace} share={share} setShare={setShare} />
</main>
</div>
</SpaceEnsurer>
</AuthenticationEnsurer>
)
}

0 comments on commit d7277fa

Please sign in to comment.