fix: use corrected user ids for submission fields on the api

This commit is contained in:
Aarnav Tale
2025-05-18 11:34:09 -04:00
parent 662c38ea44
commit d6fbc3b5ad
5 changed files with 23 additions and 12 deletions
+8
View File
@@ -1,3 +1,4 @@
import { Key, useState } from 'react';
import Dialog from '~/components/Dialog'; import Dialog from '~/components/Dialog';
import Select from '~/components/Select'; import Select from '~/components/Select';
import type { Machine, User } from '~/types'; import type { Machine, User } from '~/types';
@@ -10,6 +11,8 @@ interface MoveProps {
} }
export default function Move({ machine, users, isOpen, setIsOpen }: MoveProps) { export default function Move({ machine, users, isOpen, setIsOpen }: MoveProps) {
const [userId, setUserId] = useState<Key | null>(null);
return ( return (
<Dialog isOpen={isOpen} onOpenChange={setIsOpen}> <Dialog isOpen={isOpen} onOpenChange={setIsOpen}>
<Dialog.Panel> <Dialog.Panel>
@@ -19,11 +22,16 @@ export default function Move({ machine, users, isOpen, setIsOpen }: MoveProps) {
</Dialog.Text> </Dialog.Text>
<input type="hidden" name="action_id" value="reassign" /> <input type="hidden" name="action_id" value="reassign" />
<input type="hidden" name="node_id" value={machine.id} /> <input type="hidden" name="node_id" value={machine.id} />
<input type="hidden" name="user_id" value={userId?.toString()} />
<Select <Select
isRequired
label="Owner" label="Owner"
name="user" name="user"
placeholder="Select a user" placeholder="Select a user"
defaultSelectedKey={machine.user.id} defaultSelectedKey={machine.user.id}
onSelectionChange={(key) => {
setUserId(key);
}}
> >
{users.map((user) => ( {users.map((user) => (
<Select.Item key={user.id}>{user.name}</Select.Item> <Select.Item key={user.id}>{user.name}</Select.Item>
+2 -2
View File
@@ -251,9 +251,9 @@ async function reassignMachine(
nodeId: string, nodeId: string,
context: LoadContext, context: LoadContext,
) { ) {
const user = formData.get('user')?.toString(); const user = formData.get('user_id')?.toString();
if (!user) { if (!user) {
throw data('Missing `user` in the form data.', { throw data('Missing `user_id` in the form data.', {
status: 400, status: 400,
}); });
} }
+5 -5
View File
@@ -45,9 +45,9 @@ async function addPreAuthKey(
apiKey: string, apiKey: string,
context: LoadContext, context: LoadContext,
) { ) {
const user = formData.get('user')?.toString(); const user = formData.get('user_id')?.toString();
if (!user) { if (!user) {
return data('Missing `user` in the form data.', { return data('Missing `user_id` in the form data.', {
status: 400, status: 400,
}); });
} }
@@ -83,7 +83,7 @@ async function addPreAuthKey(
'v1/preauthkey', 'v1/preauthkey',
apiKey, apiKey,
{ {
user: user, user,
ephemeral: ephemeral === 'on', ephemeral: ephemeral === 'on',
reusable: reusable === 'on', reusable: reusable === 'on',
expiration: date.toISOString(), expiration: date.toISOString(),
@@ -106,9 +106,9 @@ async function expirePreAuthKey(
}); });
} }
const user = formData.get('user')?.toString(); const user = formData.get('user_id')?.toString();
if (!user) { if (!user) {
return data('Missing `user` in the form data.', { return data('Missing `user_id` in the form data.', {
status: 400, status: 400,
}); });
} }
@@ -1,4 +1,4 @@
import { useState } from 'react'; import { Key, useState } from 'react';
import { useFetcher } from 'react-router'; import { useFetcher } from 'react-router';
import Dialog from '~/components/Dialog'; import Dialog from '~/components/Dialog';
import Link from '~/components/Link'; import Link from '~/components/Link';
@@ -15,6 +15,7 @@ interface AddAuthKeyProps {
export default function AddAuthKey(data: AddAuthKeyProps) { export default function AddAuthKey(data: AddAuthKeyProps) {
const [reusable, setReusable] = useState(false); const [reusable, setReusable] = useState(false);
const [ephemeral, setEphemeral] = useState(false); const [ephemeral, setEphemeral] = useState(false);
const [userId, setUserId] = useState<Key | null>(data.users[0]?.id);
return ( return (
<Dialog> <Dialog>
@@ -22,6 +23,7 @@ export default function AddAuthKey(data: AddAuthKeyProps) {
<Dialog.Panel> <Dialog.Panel>
<Dialog.Title>Generate auth key</Dialog.Title> <Dialog.Title>Generate auth key</Dialog.Title>
<input type="hidden" name="action_id" value="add_preauthkey" /> <input type="hidden" name="action_id" value="add_preauthkey" />
<input type="hidden" name="user_id" value={userId?.toString()} />
<Select <Select
isRequired isRequired
label="User" label="User"
@@ -29,9 +31,12 @@ export default function AddAuthKey(data: AddAuthKeyProps) {
placeholder="Select a user" placeholder="Select a user"
description="This is the user machines will belong to when they authenticate." description="This is the user machines will belong to when they authenticate."
className="mb-2" className="mb-2"
onSelectionChange={(value) => {
setUserId(value);
}}
> >
{data.users.map((user) => ( {data.users.map((user) => (
<Select.Item key={user.name}>{user.name}</Select.Item> <Select.Item key={user.id}>{user.name}</Select.Item>
))} ))}
</Select> </Select>
<NumberInput <NumberInput
@@ -13,9 +13,7 @@ export default function ExpireAuthKey({ authKey, user }: ExpireAuthKeyProps) {
<Dialog.Panel variant="destructive"> <Dialog.Panel variant="destructive">
<Dialog.Title>Expire auth key?</Dialog.Title> <Dialog.Title>Expire auth key?</Dialog.Title>
<input type="hidden" name="action_id" value="expire_preauthkey" /> <input type="hidden" name="action_id" value="expire_preauthkey" />
{/* TODO: Why is Headscale using email as the user ID here? <input type="hidden" name="user_id" value={user.id} />
https://github.com/juanfont/headscale/issues/2520 */}
<input type="hidden" name="user" value={user.name} />
<input type="hidden" name="key" value={authKey.key} /> <input type="hidden" name="key" value={authKey.key} />
<Dialog.Text> <Dialog.Text>
Expiring this authentication key will immediately prevent it from Expiring this authentication key will immediately prevent it from