Implement legacy redirect resolution by username
cgen-8493dc116d6744669f16f0733550c848
This commit is contained in:
parent
d0892bac07
commit
70255a61f1
1 changed files with 44 additions and 1 deletions
|
|
@ -1,7 +1,50 @@
|
|||
import { useEffect, useState } from "react";
|
||||
import { Navigate, useParams } from "react-router-dom";
|
||||
import LoadingScreen from "@/components/LoadingScreen";
|
||||
import { aethexUserService } from "@/lib/aethex-database-adapter";
|
||||
|
||||
export default function LegacyPassportRedirect() {
|
||||
const { id } = useParams<{ id?: string }>();
|
||||
const target = id ? `/passport/${id}` : "/passport/me";
|
||||
const [target, setTarget] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
|
||||
const resolveTarget = async () => {
|
||||
if (!id || id === "me") {
|
||||
setTarget("/passport/me");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const profile = await aethexUserService.getProfileById(id);
|
||||
if (cancelled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (profile?.username) {
|
||||
setTarget(`/passport/${profile.username}`);
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn("Failed to resolve legacy passport redirect", error);
|
||||
}
|
||||
|
||||
if (!cancelled) {
|
||||
setTarget(`/passport/${id}`);
|
||||
}
|
||||
};
|
||||
|
||||
resolveTarget();
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [id]);
|
||||
|
||||
if (!target) {
|
||||
return <LoadingScreen message="Redirecting to passport..." />;
|
||||
}
|
||||
|
||||
return <Navigate to={target} replace />;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue