mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-23 00:22:19 +01:00
fix: SA unique token bug (#2901)
Fixes a small bug on service account token creation where the tokens the new one was being validated against were not the most up-to-date ones.
This commit is contained in:
parent
b3fcc97f93
commit
90d7737338
@ -7,21 +7,21 @@ import {
|
|||||||
PersonalAPITokenForm,
|
PersonalAPITokenForm,
|
||||||
} from 'component/user/Profile/PersonalAPITokensTab/CreatePersonalAPIToken/PersonalAPITokenForm/PersonalAPITokenForm';
|
} from 'component/user/Profile/PersonalAPITokensTab/CreatePersonalAPIToken/PersonalAPITokenForm/PersonalAPITokenForm';
|
||||||
import { ICreatePersonalApiTokenPayload } from 'hooks/api/actions/usePersonalAPITokensApi/usePersonalAPITokensApi';
|
import { ICreatePersonalApiTokenPayload } from 'hooks/api/actions/usePersonalAPITokensApi/usePersonalAPITokensApi';
|
||||||
import { IServiceAccount } from 'interfaces/service-account';
|
import { IPersonalAPIToken } from 'interfaces/personalAPIToken';
|
||||||
|
|
||||||
const DEFAULT_EXPIRATION = ExpirationOption['30DAYS'];
|
const DEFAULT_EXPIRATION = ExpirationOption['30DAYS'];
|
||||||
|
|
||||||
interface IServiceAccountCreateTokenDialogProps {
|
interface IServiceAccountCreateTokenDialogProps {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
||||||
serviceAccount: IServiceAccount;
|
tokens: IPersonalAPIToken[];
|
||||||
onCreateClick: (newToken: ICreatePersonalApiTokenPayload) => void;
|
onCreateClick: (newToken: ICreatePersonalApiTokenPayload) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ServiceAccountCreateTokenDialog = ({
|
export const ServiceAccountCreateTokenDialog = ({
|
||||||
open,
|
open,
|
||||||
setOpen,
|
setOpen,
|
||||||
serviceAccount,
|
tokens,
|
||||||
onCreateClick,
|
onCreateClick,
|
||||||
}: IServiceAccountCreateTokenDialogProps) => {
|
}: IServiceAccountCreateTokenDialogProps) => {
|
||||||
const [patDescription, setPatDescription] = useState('');
|
const [patDescription, setPatDescription] = useState('');
|
||||||
@ -40,9 +40,7 @@ export const ServiceAccountCreateTokenDialog = ({
|
|||||||
}, [open]);
|
}, [open]);
|
||||||
|
|
||||||
const isDescriptionUnique = (description: string) =>
|
const isDescriptionUnique = (description: string) =>
|
||||||
!serviceAccount.tokens?.some(
|
!tokens?.some(token => token.description === description);
|
||||||
token => token.description === description
|
|
||||||
);
|
|
||||||
|
|
||||||
const isPATValid =
|
const isPATValid =
|
||||||
patDescription.length &&
|
patDescription.length &&
|
||||||
|
@ -322,7 +322,7 @@ export const ServiceAccountTokens = ({
|
|||||||
<ServiceAccountCreateTokenDialog
|
<ServiceAccountCreateTokenDialog
|
||||||
open={createOpen}
|
open={createOpen}
|
||||||
setOpen={setCreateOpen}
|
setOpen={setCreateOpen}
|
||||||
serviceAccount={serviceAccount}
|
tokens={tokens}
|
||||||
onCreateClick={onCreateClick}
|
onCreateClick={onCreateClick}
|
||||||
/>
|
/>
|
||||||
<ServiceAccountTokenDialog
|
<ServiceAccountTokenDialog
|
||||||
|
Loading…
Reference in New Issue
Block a user