0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

Changed staff token to fetch on request (#18132)

no issue

- Solves an issue where it didn't fetch the updated staff token after
saving and still used the cached one which is invalidated.
---

<!-- Leave the line below if you'd like GitHub Copilot to generate a
summary from your commit -->
<!--
copilot:summary
-->
### <samp>🤖 Generated by Copilot at 9a59225</samp>

Improved staff token handling in `UserDetailModal` component. This
component fetches and displays a staff token for a user in the general
settings, and prevents editing or errors.
This commit is contained in:
Ronald Langeveld 2023-09-14 15:03:35 +07:00 committed by GitHub
parent 00e598b365
commit 34db31a2a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -440,7 +440,9 @@ const Password: React.FC<UserDetailProps> = ({user}) => {
};
const StaffToken: React.FC<UserDetailProps> = () => {
const {data: {apiKey} = {}} = getStaffToken();
const {refetch: apiKey} = getStaffToken({
enabled: false
});
const [token, setToken] = useState('');
const {mutateAsync: newApiKey} = genStaffToken();
const [copied, setCopied] = useState(false);
@ -454,7 +456,13 @@ const StaffToken: React.FC<UserDetailProps> = () => {
};
useEffect(() => {
setToken(apiKey?.secret || '');
const getApiKey = async () => {
const newAPI = await apiKey();
if (newAPI) {
setToken(newAPI?.data?.apiKey?.secret || '');
}
};
getApiKey();
} , [apiKey]);
const genConfirmation = () => {
@ -477,6 +485,7 @@ const StaffToken: React.FC<UserDetailProps> = () => {
title='Staff access token'
>
<TextField
readOnly={true}
rightPlaceholder={
<div className='flex'>
<Button className='mt-2' color='white' label='Regenerate' size='sm' onClick={genConfirmation} />
@ -485,7 +494,7 @@ const StaffToken: React.FC<UserDetailProps> = () => {
}
title="Staff access token"
type="text"
value={token}
value={token || ''}
/>
</SettingGroup>
);