mirror of
https://github.com/ramvignesh-b/pi-ku.git
synced 2026-05-04 08:56:52 +00:00
refactor: update route related simplifications
This commit is contained in:
@@ -4,8 +4,9 @@ import { useAuth } from "../hooks/useAuth";
|
|||||||
import SplashScreen from "./SplashScreen";
|
import SplashScreen from "./SplashScreen";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Post-login routes.
|
* Private route guard.
|
||||||
* Redirects to /login if not already authenticated.
|
* If not authenticated, capture the current url in route
|
||||||
|
* state so the Login component can link them back after sign-in
|
||||||
*/
|
*/
|
||||||
export function ProtectedRoute({ children }: { children: React.ReactNode }) {
|
export function ProtectedRoute({ children }: { children: React.ReactNode }) {
|
||||||
const { isAuthenticated, isInitializing } = useAuth();
|
const { isAuthenticated, isInitializing } = useAuth();
|
||||||
@@ -14,7 +15,6 @@ export function ProtectedRoute({ children }: { children: React.ReactNode }) {
|
|||||||
if (isInitializing) return <SplashScreen />;
|
if (isInitializing) return <SplashScreen />;
|
||||||
|
|
||||||
if (!isAuthenticated) {
|
if (!isAuthenticated) {
|
||||||
// Save the intended location to redirect back after login
|
|
||||||
return <Navigate to={ROUTES.LOGIN} state={{ from: location }} replace />;
|
return <Navigate to={ROUTES.LOGIN} state={{ from: location }} replace />;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,8 +22,8 @@ export function ProtectedRoute({ children }: { children: React.ReactNode }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pre-login flows.
|
* Public - auth route guard.
|
||||||
* Redirects to /drawer if already authenticated.
|
* If authenticated, redirect all the auth related flows to the drawer
|
||||||
*/
|
*/
|
||||||
export function PublicRoute({ children }: { children: React.ReactNode }) {
|
export function PublicRoute({ children }: { children: React.ReactNode }) {
|
||||||
const { isAuthenticated, isInitializing } = useAuth();
|
const { isAuthenticated, isInitializing } = useAuth();
|
||||||
|
|||||||
@@ -9,14 +9,14 @@ export const endpoints = {
|
|||||||
LETTERS: "/api/letters/",
|
LETTERS: "/api/letters/",
|
||||||
};
|
};
|
||||||
|
|
||||||
// simple utility to handle path params
|
// constructs dynamic path params for activate flow
|
||||||
export const replacePathParams = (
|
export const replacePathParams = (
|
||||||
url: string,
|
url: string,
|
||||||
params: Record<string, string>,
|
params: Record<string, string>,
|
||||||
): string => {
|
): string => {
|
||||||
let result = url;
|
let constructedUrl = url;
|
||||||
for (const [key, value] of Object.entries(params)) {
|
for (const [key, value] of Object.entries(params)) {
|
||||||
result = result.replace(`:${key}`, value);
|
constructedUrl = constructedUrl.replace(`:${key}`, value);
|
||||||
}
|
}
|
||||||
return result;
|
return constructedUrl;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Route PATTERNS
|
// Page Route PATTERNS
|
||||||
export const ROUTES = {
|
export const ROUTES = {
|
||||||
HOME: "/",
|
HOME: "/",
|
||||||
ONBOARD: "/onboard",
|
ONBOARD: "/onboard",
|
||||||
@@ -6,13 +6,12 @@ export const ROUTES = {
|
|||||||
ACTIVATE: "/activate/:uidb64/:token",
|
ACTIVATE: "/activate/:uidb64/:token",
|
||||||
LOGIN: "/login",
|
LOGIN: "/login",
|
||||||
DRAWER: "/drawer",
|
DRAWER: "/drawer",
|
||||||
WRITE: "/quill/:public_id?", // ← static pattern
|
WRITE: "/quill/:public_id?",
|
||||||
READ: "/read/:public_id",
|
READ: "/read/:public_id",
|
||||||
};
|
};
|
||||||
|
|
||||||
// Path BUILDERS
|
// Dynamic path BUILDERS
|
||||||
export const PATHS = {
|
export const PATHS = {
|
||||||
write: (public_id?: string) => `/quill/${public_id ?? ""}`,
|
write: (public_id?: string) => `/quill/${public_id ?? ""}`,
|
||||||
read: (public_id: string) => `/read/${public_id}`,
|
read: (public_id: string) => `/read/${public_id}`,
|
||||||
activate: (uidb64: string, token: string) => `/activate/${uidb64}/${token}`,
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user