Skip to content

Commit 2cc3f2d

Browse files
authored
Correct inconsistencies w/ ckey entry handling (#7)
1 parent 74715ca commit 2cc3f2d

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

frontend/src/components/authentikPanel.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,17 @@ export const AuthentikPanel: React.FC = () => {
9292
const handleAddUser = async () => {
9393
if (!addCkey.trim()) return;
9494

95+
const re = /[^a-z0-9@]/g;
96+
const userCkeyChecked = addCkey.trim().toLowerCase().replace(re, "");
97+
if (!userCkeyChecked) return;
98+
9599
setAddLoading(true);
96100
try {
97101
const response = await callApi("/Authentik/AddUserToGroup", {
98102
method: "POST",
99103
headers: { "Content-Type": "application/json" },
100104
body: JSON.stringify({
101-
ckey: addCkey.trim(),
105+
ckey: userCkeyChecked,
102106
group_name: selectedGroup,
103107
}),
104108
});
@@ -108,7 +112,7 @@ export const AuthentikPanel: React.FC = () => {
108112
throw new Error(err.message || "Failed to add user to group");
109113
}
110114

111-
global?.updateAndShowToast(`Added ${addCkey} to ${selectedGroup}`);
115+
global?.updateAndShowToast(`Added ${userCkeyChecked} to ${selectedGroup}`);
112116
setShowAddDialog(false);
113117
setAddCkey("");
114118
fetchGroupMembers(selectedGroup);

frontend/src/components/userLookup.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ export const LookupMenu: React.FC<LookupMenuProps> = (
5353
(args: UpdateUserArguments) => {
5454
const { userCkey, userDiscordId } = args;
5555
setLoading(true);
56-
const re = /[\\^]|[^a-z0-9@]/g;
57-
const userCkeyChecked = userCkey?.toLowerCase().replace(re, "");
56+
const re = /[^a-z0-9@]/g;
57+
const userCkeyChecked = userCkey?.trim().toLowerCase().replace(re, "");
5858
callApi(
5959
userCkeyChecked
6060
? `/User?ckey=${userCkeyChecked}`
@@ -92,10 +92,11 @@ export const LookupMenu: React.FC<LookupMenuProps> = (
9292

9393
if (!potentialUser) return;
9494

95-
const re = /[\\^]|[^a-z0-9@]/g;
96-
const checked = potentialUser.toLowerCase().replace(re, "");
95+
const re = /[^a-z0-9@]/g;
96+
const checked = potentialUser.trim().toLowerCase().replace(re, "");
97+
if(!checked) return;
9798

98-
if (potentialUser && (!userData || userData.ckey !== checked)) {
99+
if (!userData || userData.ckey !== checked) {
99100
updateUser({ userCkey: potentialUser as string });
100101
}
101102
}, [value, userData, discordId, updateUser, potentialUser, user, loading]);
@@ -1216,7 +1217,9 @@ const KnownAltsModal = (props: { player: Player }) => {
12161217
if (!player.ckey || !newAltCkey.trim()) return;
12171218

12181219
const playerCkey = altsData?.mainAccount || player.ckey;
1219-
const altCkey = newAltCkey.trim().toLowerCase().replace(/[^a-z0-9@]/g, "");
1220+
const re = /[^a-z0-9@]/g;
1221+
const altCkey = newAltCkey.trim().toLowerCase().replace(re, "");
1222+
if (!altCkey) return;
12201223

12211224
callApi("/User/KnownAlts", {
12221225
method: "POST",

0 commit comments

Comments
 (0)