Skip to content

Commit 2a9cf0b

Browse files
jasonmoraisCopilot
andauthored
feat(ui-admin): require auth for all admin pages and fix header text … (#372)
* feat(ui-admin): require auth for all admin pages and fix header text size - Wrap AppRoutes in RequireAuth with redirectPath=/login so all admin pages require authentication including the home page - Update listing-operations and user-operations redirect paths from / to /login - Remove redundant RequireAuth wrapper from messages route in app-routes.tsx - Remove unused isAuthenticated prop from App component and its caller - Fix admin header .brandName font-size from 1.1rem to 24px, add line-height: 32px, and update color to match canonical .logoText style Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * removed some uneeded logic for admin portal --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e22dcea commit 2a9cf0b

10 files changed

Lines changed: 37 additions & 64 deletions

File tree

apps/ui-admin/src/app.container.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const AppContainer: FC = () => {
1313
});
1414

1515
if (!auth.isAuthenticated) {
16-
return <App isAuthenticated={false} />;
16+
return <App />;
1717
}
1818

1919
const user = data?.currentAdminUser;
@@ -26,7 +26,7 @@ export const AppContainer: FC = () => {
2626
error={error}
2727
hasDataComponent={
2828
<UserIdProvider userId={userId}>
29-
<App isAuthenticated={auth.isAuthenticated} />
29+
<App />
3030
</UserIdProvider>
3131
}
3232
/>

apps/ui-admin/src/app.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,28 @@ import { RequireAuth } from '@sthrift/ui-admin-route-shared';
99
import { UserOperationsRoutes } from '@sthrift/ui-admin-route-user-operations';
1010
import type React from 'react';
1111

12+
const appSection = (
13+
<RequireAuth redirectPath="/login">
14+
<AppRoutes />
15+
</RequireAuth>
16+
);
17+
1218
const listingOperationsSection = (
13-
<RequireAuth redirectPath="/">
19+
<RequireAuth redirectPath="/login">
1420
<ListingOperationsRoutes />
1521
</RequireAuth>
1622
);
1723

1824
const userOperationsSection = (
19-
<RequireAuth redirectPath="/">
25+
<RequireAuth redirectPath="/login">
2026
<UserOperationsRoutes />
2127
</RequireAuth>
2228
);
2329

24-
interface AppProps {
25-
isAuthenticated: boolean;
26-
}
27-
export const App: React.FC<AppProps> = () => {
30+
export const App: React.FC = () => {
2831
return (
2932
<Routes>
30-
<Route path="/*" element={<AppRoutes />} />
33+
<Route path="/*" element={appSection} />
3134
<Route path="/login" element={<AdminLogin />} />
3235
<Route path="/auth-redirect" element={<AuthRedirect />} />
3336
<Route

packages/sthrift/ui-admin-route-listing-operations/src/section-layout.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ export const SectionLayout: React.FC = () => {
5656
return () => window.removeEventListener('resize', handleResize);
5757
}, [auth.isAuthenticated]);
5858

59-
const handleOnLogin = () => {
60-
navigate('/login');
61-
};
62-
6359
const handleLogOut = () => {
6460
HandleLogout(auth, apolloClient, window.location.origin);
6561
};
@@ -93,7 +89,6 @@ export const SectionLayout: React.FC = () => {
9389
>
9490
<AdminHeader
9591
isAuthenticated={auth.isAuthenticated}
96-
onLogin={handleOnLogin}
9792
onLogout={handleLogOut}
9893
/>
9994
<div

packages/sthrift/ui-admin-route-root/src/admin-login.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const AdminLogin: React.FC = () => {
1313
const [submitting, setSubmitting] = useState(false);
1414
const navigate = useNavigate();
1515
const auth = useAuth();
16+
const handleBack = () => undefined;
1617

1718
const handleLogin = (_values: LoginFormData) => {
1819
setSubmitting(true);
@@ -23,25 +24,17 @@ export const AdminLogin: React.FC = () => {
2324
}
2425
};
2526

26-
const handleBack = () => {
27-
navigate('/');
28-
};
29-
30-
const handleOnLogin = () => {
31-
globalThis.location.href = '/auth-redirect';
32-
};
33-
3427
return (
3528
<LoginForm
3629
title="Admin Log In"
3730
emailPlaceholder="admin@sharethrift.com"
3831
onSubmit={handleLogin}
3932
submitting={submitting}
4033
onBack={handleBack}
34+
showBack={false}
4135
headerSlot={
4236
<AdminHeader
4337
isAuthenticated={auth.isAuthenticated}
44-
onLogin={handleOnLogin}
4538
onLogout={() => navigate('/')}
4639
/>
4740
}

packages/sthrift/ui-admin-route-root/src/app-routes.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Route, Routes } from 'react-router-dom';
2-
import { RequireAuth } from '@sthrift/ui-admin-route-shared';
32
import { SectionLayout } from './section-layout.tsx';
43
import { Listings } from './components/pages/home/pages/all-listings-page.tsx';
54
import { ViewListing } from './components/pages/view-listing/pages/view-listing-page.tsx';
@@ -11,14 +10,7 @@ export const AppRoutes: React.FC = () => {
1110
<Route path="" element={<SectionLayout />}>
1211
<Route path="" element={<Listings />} />
1312
<Route path="listing/:listingId" element={<ViewListing />} />
14-
<Route
15-
path="messages/*"
16-
element={
17-
<RequireAuth redirectPath="/">
18-
<MessagesRoutes />
19-
</RequireAuth>
20-
}
21-
/>
13+
<Route path="messages/*" element={<MessagesRoutes />} />
2214
</Route>
2315
</Routes>
2416
);

packages/sthrift/ui-admin-route-root/src/section-layout.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ export const SectionLayout: React.FC = () => {
5656
return () => window.removeEventListener('resize', handleResize);
5757
}, [auth.isAuthenticated]);
5858

59-
const handleOnLogin = () => {
60-
navigate('/login');
61-
};
62-
6359
const handleLogOut = () => {
6460
HandleLogout(auth, apolloClient, window.location.origin);
6561
};
@@ -93,7 +89,6 @@ export const SectionLayout: React.FC = () => {
9389
>
9490
<AdminHeader
9591
isAuthenticated={auth.isAuthenticated}
96-
onLogin={handleOnLogin}
9792
onLogout={handleLogOut}
9893
/>
9994
<div

packages/sthrift/ui-admin-route-shared/src/admin-header.module.css

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@
3737

3838
.brandName {
3939
font-family: var(--Urbanist);
40-
font-size: 1.1rem;
40+
font-size: 24px;
4141
font-weight: 700;
42+
line-height: 32px;
4243
letter-spacing: 0.02em;
43-
color: var(--color-message-text);
44+
color: var(--color-primary);
4445
text-transform: lowercase;
4546
}
4647

@@ -87,7 +88,7 @@
8788
}
8889

8990
.brandName {
90-
font-size: 1rem;
91+
font-size: 20px;
9192
}
9293

9394
.portalPill {

packages/sthrift/ui-admin-route-shared/src/admin-header.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ import styles from './admin-header.module.css';
66

77
interface AdminHeaderProps {
88
isAuthenticated: boolean;
9-
onLogin?: () => void;
109
onLogout?: () => void;
1110
}
1211

1312
const { Header: AntHeader } = Layout;
1413

1514
export const AdminHeader: React.FC<AdminHeaderProps> = ({
1615
isAuthenticated,
17-
onLogin,
1816
onLogout,
1917
}) => {
2018
return (
@@ -35,15 +33,7 @@ export const AdminHeader: React.FC<AdminHeaderProps> = ({
3533
>
3634
Log Out
3735
</Button>
38-
) : (
39-
<Button
40-
type="link"
41-
className={styles['authButton']}
42-
onClick={onLogin}
43-
>
44-
Log In
45-
</Button>
46-
)}
36+
) : null}
4737
</nav>
4838
</AntHeader>
4939
);

packages/sthrift/ui-admin-route-user-operations/src/section-layout.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ export const SectionLayout: React.FC = () => {
5656
return () => window.removeEventListener('resize', handleResize);
5757
}, [auth.isAuthenticated]);
5858

59-
const handleOnLogin = () => {
60-
navigate('/login');
61-
};
62-
6359
const handleLogOut = () => {
6460
HandleLogout(auth, apolloClient, window.location.origin);
6561
};
@@ -93,7 +89,6 @@ export const SectionLayout: React.FC = () => {
9389
>
9490
<AdminHeader
9591
isAuthenticated={auth.isAuthenticated}
96-
onLogin={handleOnLogin}
9792
onLogout={handleLogOut}
9893
/>
9994
<div

packages/sthrift/ui-shared/src/organisms/login-form.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface LoginFormProps {
1818
onBack: () => void;
1919
headerSlot: React.ReactNode;
2020
footerSlot?: React.ReactNode;
21+
showBack?: boolean;
2122
showForgotPassword?: boolean;
2223
onForgotPassword?: () => void;
2324
}
@@ -30,6 +31,7 @@ export const LoginForm: React.FC<LoginFormProps> = ({
3031
onBack,
3132
headerSlot,
3233
footerSlot,
34+
showBack = true,
3335
showForgotPassword,
3436
onForgotPassword,
3537
}) => {
@@ -166,17 +168,24 @@ export const LoginForm: React.FC<LoginFormProps> = ({
166168
<div
167169
style={{
168170
display: 'flex',
169-
justifyContent: showForgotPassword ? 'space-between' : 'flex-start',
171+
justifyContent:
172+
showBack && showForgotPassword
173+
? 'space-between'
174+
: showBack
175+
? 'flex-start'
176+
: 'flex-end',
170177
marginTop: '1rem',
171178
}}
172179
>
173-
<Button
174-
type="link"
175-
onClick={onBack}
176-
style={{ padding: 0 }}
177-
>
178-
← Back to Home
179-
</Button>
180+
{showBack && (
181+
<Button
182+
type="link"
183+
onClick={onBack}
184+
style={{ padding: 0 }}
185+
>
186+
← Back to Home
187+
</Button>
188+
)}
180189
{showForgotPassword && onForgotPassword && (
181190
<Button
182191
type="link"

0 commit comments

Comments
 (0)