Skip to content

Commit

Permalink
refactor: routes
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrunton committed Aug 31, 2024
1 parent fbc9d26 commit 8d57316
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
7 changes: 4 additions & 3 deletions client/src/features/auth/organisms/require-auth.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from 'react'
import React, { PropsWithChildren } from 'react'
import { LoadingIndicator } from '../../../shared/molecules/loading-indicator'
import { setRedirectPath } from '../pages/callback'
import { useAuth } from '..'
import { Outlet } from 'react-router-dom'

export const RequireAuth: React.FC<{ children: React.ReactNode }> = ({ children }) => {
export const RequireAuth: React.FC<PropsWithChildren> = ({ children }) => {
const { isAuthenticated, isLoading, signIn } = useAuth()

if (isAuthenticated) {
return <>{children}</>
return <>{children ?? <Outlet />}</>
}

if (!isLoading) {
Expand Down
26 changes: 12 additions & 14 deletions client/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,18 @@ export const router = createBrowserRouter([
element: <Callback />,
},
{
path: '/room/new',
element: (
<RequireAuth>
<NewRoomPage />
</RequireAuth>
),
},
{
path: '/room/:roomId',
element: (
<RequireAuth>
<RoomPage />
</RequireAuth>
),
path: '/room',
element: <RequireAuth />,
children: [
{
path: 'new',
element: <NewRoomPage />,
},
{
path: ':roomId',
element: <RoomPage />,
},
],
},
],
},
Expand Down
4 changes: 2 additions & 2 deletions client/src/shared/navigation/organisms/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import { useAuth } from '../../../features/auth'
import { HeaderTemplate } from '../molecules/header-template'

export const Header = () => {
const { isAuthenticated, isLoading: isLoadingAuth } = useAuth()
const { isAuthenticated } = useAuth()
const { roomId } = useParams()
const { data: roomResponse } = useRoom(roomId, { enabled: !isLoadingAuth })
const { data: roomResponse } = useRoom(roomId, { enabled: isAuthenticated })

const { isOpen, onOpen, onClose } = useDisclosure()

Expand Down

0 comments on commit 8d57316

Please sign in to comment.