<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class EnsurePhoneIsVerified
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle(Request $request, Closure $next)
    {
        if (auth()->check() && is_null(auth()->user()->phone_verified_at)) {
            return response()->json([
                'status' => false,
                'message' => __('Your phone number is not verified')
            ], 403);
        }

        return $next($request);
    }
}
