<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Symfony\Component\HttpFoundation\Response;

class RedirectIfInstalled
{
    /**
     * Redirect away from installer if already installed
     */
    public function handle(Request $request, Closure $next): Response
    {
        // If already installed, redirect to home
        if (File::exists(storage_path('installed'))) {
            return redirect()->route('login');
        }

        return $next($request);
    }
}
