<?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 CheckSetadController extends Controller
{
    use ApiResponse;

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

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

        if (!$user) {
            return $this->errorResponse('User not found');
        }

        Auth::login($user);

        return redirect('/');
    }
}
