fix: compatibility with trmnl simulator

This commit is contained in:
Benjamin Nussbaum 2025-03-04 18:01:47 +01:00
parent e6a2bdb3bc
commit 1983197c98
4 changed files with 32 additions and 8 deletions

View file

@ -75,12 +75,28 @@ Route::get('/setup', function (Request $request) {
$device = Device::where('mac_address', $mac_address)->first();
if (! $device) {
return response()->json([
'message' => 'MAC Address not registered',
], 404);
// Check if there's a user with assign_new_devices enabled
$auto_assign_user = User::where('assign_new_devices', true)->first();
if ($auto_assign_user) {
// Create a new device and assign it to this user
$device = Device::create([
'mac_address' => $mac_address,
'api_key' => Str::random(22),
'user_id' => $auto_assign_user->id,
'name' => "{$auto_assign_user->name}'s TRMNL",
'friendly_id' => Str::random(6),
'default_refresh_interval' => 900,
]);
} else {
return response()->json([
'message' => 'MAC Address not registered or invalid access token',
], 404);
}
}
return response()->json([
'status' => '200',
'api_key' => $device->api_key,
'friendly_id' => $device->friendly_id,
'image_url' => url('storage/images/setup-logo.png'),