<?php

namespace App\Http\Middleware;

use Closure;
use App\Helper\OutlookHelper;
use Illuminate\Support\Facades\Auth;

class RefreshOutlookToken
{
    public function handle($request, Closure $next)
    {
        $user = Auth::user();

        if ($user->outlook_access_token && now()->greaterThan($user->outlook_token_expiry)) {
            OutlookHelper::refreshToken($user);
        }

        return $next($request);
    }
}
