Files
lolympus-tournament-support/apps/web/src/components/DevAuthSwitcher.tsx
T

69 lines
1.9 KiB
TypeScript

import { useState } from 'react';
import { useQueryClient } from '@tanstack/react-query';
import { setAuthUserId, useAuthUserId } from '../config';
export default function DevAuthSwitcher() {
const authUserId = useAuthUserId();
if (!import.meta.env.DEV) {
return null;
}
return (
<DevAuthSwitcherForm
key={authUserId ?? 'no-auth-user'}
authUserId={authUserId}
/>
);
}
function DevAuthSwitcherForm({
authUserId,
}: {
authUserId: string | null;
}) {
const queryClient = useQueryClient();
const [inputValue, setInputValue] = useState(authUserId ?? '');
function updateAuthUserId(nextValue: string | null) {
setAuthUserId(nextValue);
void queryClient.invalidateQueries();
}
return (
<div className="fixed right-4 bottom-4 z-50 w-72 border border-base-content/10 bg-base-100/95 backdrop-blur px-3 py-3 shadow-xl">
<div className="text-xs font-bold uppercase tracking-wider text-base-content/35">
Dev Auth
</div>
<div className="mt-2 text-xs text-base-content/45">
X-Auth-User-Id
</div>
<input
value={inputValue}
onChange={(event) => setInputValue(event.target.value)}
placeholder="Mongo User ID"
className="mt-1 w-full border border-base-content/10 bg-transparent px-2 py-2 text-xs text-base-content focus:outline-none focus:border-primary/30"
/>
<div className="mt-2 flex items-center gap-2">
<button
type="button"
className="btn btn-primary btn-xs px-3"
onClick={() => updateAuthUserId(inputValue)}
>
Set
</button>
<button
type="button"
className="btn btn-ghost btn-xs px-3"
onClick={() => updateAuthUserId(null)}
>
Clear
</button>
</div>
<div className="mt-2 text-xs text-base-content/35 break-all">
현재값: {authUserId ?? '없음'}
</div>
</div>
);
}