59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
import { useEffect, useState } from 'react';
|
|
import { useQueryClient } from '@tanstack/react-query';
|
|
import { setAuthUserId, useAuthUserId } from '../config';
|
|
|
|
export default function DevAuthSwitcher() {
|
|
const authUserId = useAuthUserId();
|
|
const queryClient = useQueryClient();
|
|
const [inputValue, setInputValue] = useState(authUserId ?? '');
|
|
|
|
useEffect(() => {
|
|
setInputValue(authUserId ?? '');
|
|
}, [authUserId]);
|
|
|
|
if (!import.meta.env.DEV) {
|
|
return null;
|
|
}
|
|
|
|
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-[10px] font-bold uppercase tracking-wider text-base-content/35">
|
|
Dev Auth
|
|
</div>
|
|
<div className="mt-2 text-[11px] 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-[10px] text-base-content/35 break-all">
|
|
현재값: {authUserId ?? '없음'}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|