fix(auth): UserMenu sessionStorage → AuthContext — unification auth state
Some checks failed
CI/CD — Build & Deploy / Build & Deploy (push) Failing after 24s
Some checks failed
CI/CD — Build & Deploy / Build & Deploy (push) Failing after 24s
This commit is contained in:
43
frontend/src/components/auth/UserMenu.tsx
Normal file
43
frontend/src/components/auth/UserMenu.tsx
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import { clearAccessToken } from '../../lib/oauth';
|
||||||
|
import { useAuthContext } from '../../context/AuthContext';
|
||||||
|
import LoginButton from './LoginButton';
|
||||||
|
|
||||||
|
interface UserMenuProps {
|
||||||
|
/** Optionnel : si fourni, prend le dessus sur le nickname de l'utilisateur */
|
||||||
|
displayName?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function UserMenu({ displayName }: UserMenuProps) {
|
||||||
|
const { user } = useAuthContext();
|
||||||
|
|
||||||
|
function handleLogout() {
|
||||||
|
clearAccessToken();
|
||||||
|
window.location.href = '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
return <LoginButton />;
|
||||||
|
}
|
||||||
|
|
||||||
|
const name = displayName ?? user.nickname ?? 'Mon compte';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
{/* Avatar placeholder */}
|
||||||
|
<span className="flex h-7 w-7 items-center justify-center rounded-full bg-od-surface border border-[#c9a84c] font-mono text-[10px] text-[#c9a84c]">
|
||||||
|
{name !== 'Mon compte' ? name[0].toUpperCase() : '●'}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<span className="font-mono text-xs text-[#c9a84c]">
|
||||||
|
{name}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={handleLogout}
|
||||||
|
className="font-mono text-xs text-od-muted hover:text-od-crit transition-colors duration-150"
|
||||||
|
>
|
||||||
|
Se déconnecter
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user