Skip to content

Commit

Permalink
fix: SA unique token bug (#2901)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nunogois committed Jan 16, 2023
1 parent b3fcc97 commit 90d7737
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
Expand Up @@ -7,21 +7,21 @@ import {
PersonalAPITokenForm,
} from 'component/user/Profile/PersonalAPITokensTab/CreatePersonalAPIToken/PersonalAPITokenForm/PersonalAPITokenForm';
import { ICreatePersonalApiTokenPayload } from 'hooks/api/actions/usePersonalAPITokensApi/usePersonalAPITokensApi';
import { IServiceAccount } from 'interfaces/service-account';
import { IPersonalAPIToken } from 'interfaces/personalAPIToken';

const DEFAULT_EXPIRATION = ExpirationOption['30DAYS'];

interface IServiceAccountCreateTokenDialogProps {
open: boolean;
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
serviceAccount: IServiceAccount;
tokens: IPersonalAPIToken[];
onCreateClick: (newToken: ICreatePersonalApiTokenPayload) => void;
}

export const ServiceAccountCreateTokenDialog = ({
open,
setOpen,
serviceAccount,
tokens,
onCreateClick,
}: IServiceAccountCreateTokenDialogProps) => {
const [patDescription, setPatDescription] = useState('');
Expand All @@ -40,9 +40,7 @@ export const ServiceAccountCreateTokenDialog = ({
}, [open]);

const isDescriptionUnique = (description: string) =>
!serviceAccount.tokens?.some(
token => token.description === description
);
!tokens?.some(token => token.description === description);

const isPATValid =
patDescription.length &&
Expand Down
Expand Up @@ -322,7 +322,7 @@ export const ServiceAccountTokens = ({
<ServiceAccountCreateTokenDialog
open={createOpen}
setOpen={setCreateOpen}
serviceAccount={serviceAccount}
tokens={tokens}
onCreateClick={onCreateClick}
/>
<ServiceAccountTokenDialog
Expand Down

0 comments on commit 90d7737

Please sign in to comment.