feat(TALE-35): add initial machine key authorization

This commit is contained in:
Aarnav Tale 2024-10-03 11:58:05 -04:00
parent d867769025
commit e8c1cadf54
No known key found for this signature in database
4 changed files with 153 additions and 2 deletions

View file

@ -97,6 +97,35 @@ export async function menuAction(request: ActionFunctionArgs['request']) {
}
}
case 'register': {
const key = data.get('mkey')?.toString()
const user = data.get('user')?.toString()
if (!key) {
return json({ message: 'No machine key provided' }, {
status: 400,
})
}
if (!user) {
return json({ message: 'No user provided' }, {
status: 400,
})
}
try {
await post('v1/node/register', session.get('hsApiKey')!, {
user, key,
})
return json({ message: 'Machine registered' })
} catch {
return json({ message: 'Failed to register machine' }, {
status: 500,
})
}
}
default: {
return json({ message: 'Invalid method' }, {
status: 400,