fix(#158): do not require ID header on /display endpoint
Some checks are pending
tests / ci (push) Waiting to run

This commit is contained in:
Benjamin Nussbaum 2026-01-13 17:24:14 +01:00
parent c2c553461f
commit d7f6237265
2 changed files with 4 additions and 6 deletions

View file

@ -18,15 +18,13 @@ use Illuminate\Support\Str;
Route::get('/display', function (Request $request) { Route::get('/display', function (Request $request) {
$mac_address = $request->header('id'); $mac_address = $request->header('id');
$access_token = $request->header('access-token'); $access_token = $request->header('access-token');
$device = Device::where('mac_address', mb_strtoupper($mac_address ?? '')) $device = Device::where('api_key', $access_token)->first();
->where('api_key', $access_token)
->first();
if (! $device) { if (! $device) {
// Check if there's a user with assign_new_devices enabled // Check if there's a user with assign_new_devices enabled
$auto_assign_user = User::where('assign_new_devices', true)->first(); $auto_assign_user = User::where('assign_new_devices', true)->first();
if ($auto_assign_user) { if ($auto_assign_user && $mac_address) {
// Create a new device and assign it to this user // Create a new device and assign it to this user
$device = Device::create([ $device = Device::create([
'mac_address' => mb_strtoupper($mac_address ?? ''), 'mac_address' => mb_strtoupper($mac_address ?? ''),
@ -39,7 +37,7 @@ Route::get('/display', function (Request $request) {
]); ]);
} else { } else {
return response()->json([ return response()->json([
'message' => 'MAC Address not registered or invalid access token', 'message' => 'MAC Address not registered (or not set), or invalid access token',
], 404); ], 404);
} }
} }

View file

@ -263,7 +263,7 @@ test('invalid device credentials return error', function (): void {
])->get('/api/display'); ])->get('/api/display');
$response->assertNotFound() $response->assertNotFound()
->assertJson(['message' => 'MAC Address not registered or invalid access token']); ->assertJson(['message' => 'MAC Address not registered (or not set), or invalid access token']);
}); });
test('log endpoint requires valid device credentials', function (): void { test('log endpoint requires valid device credentials', function (): void {