Skip to content

Commit eb4e27e

Browse files
committed
feat(portal): improve token handling and add 404 page
- Preserve URL path when processing tokens instead of always redirecting to root - Add NotFound component for better UX on invalid routes - Enable proper deep linking to portal routes like /new and /destinations/{id} This allows external applications to redirect users to specific portal pages while maintaining authentication flow.
1 parent a67bac3 commit eb4e27e

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

internal/portal/src/app.tsx

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect, useState, createContext } from "react";
2-
import { BrowserRouter, Routes, Route } from "react-router-dom";
2+
import { BrowserRouter, Routes, Route, Link } from "react-router-dom";
33
import DestinationList from "./scenes/DestinationsList/DestinationList";
44
import { SWRConfig } from "swr";
55

@@ -18,6 +18,35 @@ type ApiClient = {
1818

1919
export const ApiContext = createContext<ApiClient>({} as ApiClient);
2020

21+
function NotFound() {
22+
return (
23+
<div style={{
24+
textAlign: 'center',
25+
padding: '2rem',
26+
maxWidth: '500px',
27+
margin: '0 auto'
28+
}}>
29+
<h1 style={{ fontSize: '2rem', marginBottom: '1rem', color: '#374151' }}>
30+
Page Not Found
31+
</h1>
32+
<p style={{ fontSize: '1rem', marginBottom: '2rem', color: '#6b7280' }}>
33+
The page you're looking for doesn't exist.
34+
</p>
35+
<Link
36+
to="/"
37+
style={{
38+
color: '#3b82f6',
39+
textDecoration: 'none',
40+
fontSize: '1rem',
41+
fontWeight: '500'
42+
}}
43+
>
44+
← Back to Destinations
45+
</Link>
46+
</div>
47+
);
48+
}
49+
2150
export function App() {
2251
const token = useToken();
2352
const tenant = useTenant(token ?? undefined);
@@ -72,6 +101,7 @@ export function App() {
72101
path="/destinations/:destination_id/*"
73102
Component={Destination}
74103
/>
104+
<Route path="*" Component={NotFound} />
75105
</Routes>
76106
</SWRConfig>
77107
</ApiContext.Provider>
@@ -108,7 +138,10 @@ function useToken() {
108138
if (token) {
109139
setToken(token);
110140
sessionStorage.setItem("token", token);
111-
window.location.replace("/");
141+
142+
// Preserve the current path from the browser
143+
const currentPath = window.location.pathname;
144+
window.location.replace(currentPath);
112145
}
113146
}, []);
114147

0 commit comments

Comments
 (0)