mirror of
https://github.com/ramvignesh-b/pi-ku.git
synced 2026-05-04 08:56:52 +00:00
refactor: use proper config for routes
This commit is contained in:
@@ -15,7 +15,7 @@ export function ProtectedRoute({ children }: { children: React.ReactNode }) {
|
|||||||
|
|
||||||
if (!isAuthenticated) {
|
if (!isAuthenticated) {
|
||||||
// Save the intended location to redirect back after login
|
// Save the intended location to redirect back after login
|
||||||
return <Navigate to="/login" state={{ from: location }} replace />;
|
return <Navigate to={ROUTES.LOGIN} state={{ from: location }} replace />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <>{children}</>;
|
return <>{children}</>;
|
||||||
|
|||||||
@@ -36,17 +36,13 @@ export default function Login() {
|
|||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
setApiError(null);
|
setApiError(null);
|
||||||
try {
|
try {
|
||||||
// 1. Authenticate
|
|
||||||
const { data: authData } = await publicApi.post(endpoints.LOGIN, data);
|
const { data: authData } = await publicApi.post(endpoints.LOGIN, data);
|
||||||
|
|
||||||
// 2. Fetch User Profile with the fresh token
|
|
||||||
// We pass the header explicitly to avoid any race conditions with interceptors
|
|
||||||
const { data: userData } = await api.get(endpoints.ME, {
|
const { data: userData } = await api.get(endpoints.ME, {
|
||||||
headers: { Authorization: `Bearer ${authData.access}` },
|
headers: { Authorization: `Bearer ${authData.access}` },
|
||||||
});
|
});
|
||||||
|
|
||||||
// 3. Update store using the hook method
|
login(authData.access, userData);
|
||||||
await login(authData.access, userData);
|
|
||||||
|
|
||||||
navigate(ROUTES.DRAWER);
|
navigate(ROUTES.DRAWER);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ export default function VerifyEmail() {
|
|||||||
type="button"
|
type="button"
|
||||||
className="text-xs italic opacity-40 cursor-pointer underline"
|
className="text-xs italic opacity-40 cursor-pointer underline"
|
||||||
onClick={() => window.close()}
|
onClick={() => window.close()}
|
||||||
onKeyDown={(e) => e.key === "Enter" && window.close()}
|
|
||||||
>
|
>
|
||||||
You can close this window now.
|
You can close this window now.
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user