<?php

namespace App\Http\Controllers\ProvinceDashboard;

use App\Http\Controllers\Controller;
use app\Http\Traits\ApiResponse;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;

class VerifyAuthenticationController extends Controller
{
    use ApiResponse;

    public function login(Request $request)
    {
        if (!Hash::check(config('globalVariables.LOGIN_HASH_VALUE'), $request->token)) {
            return $this->errorResponse('Invalid token');
        }

        $user = User::query()->findOrFail($request->user_id);

        Auth::login($user);

        return redirect('/');
    }
}
