Skip to content

Commit

Permalink
fix: add SessionAuth wrapper for protected routes
Browse files Browse the repository at this point in the history
  • Loading branch information
samjcombs committed Dec 6, 2024
1 parent 601980b commit 29c2f6b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {BrowserRouter as Router, Route, Routes} from 'react-router-dom';
import SuperTokens, {SuperTokensWrapper} from 'supertokens-auth-react';
import {SessionAuth} from 'supertokens-auth-react/recipe/session';
import CallbackHandler from './CallbackHandler';
import Home from './components/ui/home';
import Login from './components/ui/login';
Expand All @@ -13,16 +14,19 @@ if (config.requireAuth) {
}

function AppRoutes() {
const protectedElement = (element: JSX.Element) =>
config.requireAuth ? <SessionAuth>{element}</SessionAuth> : element;

return (
<Router>
<Routes>
<Route
path={'/auth/callback/:providerId'}
path="/auth/callback/:providerId"
element={<CallbackHandler />}
/>
<Route path={'/auth'} element={<Login />} />
<Route path="/" element={<Home />} />
<Route path="/settings" element={<SettingsPage />} />
<Route path="/auth" element={<Login />} />
<Route path="/" element={protectedElement(<Home />)} />
<Route path="/settings" element={protectedElement(<SettingsPage />)} />
<Route path="*" element={<NotFound />} />
</Routes>
</Router>
Expand Down

0 comments on commit 29c2f6b

Please sign in to comment.