0

How can I logout a user after 48 hours.

public function generatePass(Request $request)
{
    $myRandomString = Str::random(8);
    
    DB::table('web_passes')->insert([
        'pass' => $myRandomString,
        'user_id' => $request->user_id,
        'expiry_time' =>   Carbon::now()->addDays(2)
    ]);
mqamar
  • 11
  • 4

2 Answers2

0

you can change the SESSION_LIFETIME=20 in .env

the life time of session in this example is 20 minutes

so in any request should be authorize give it

if(auth()->check()) complete execute

else

remove or refersh token to invalid and redirect to login page

Ossama Abd
  • 464
  • 2
  • 10
0

I just did that by simply applying a middleware condition

 public function handle(Request $request, Closure $next)
    {
        $webPass = $request->user()->webPass;
        if($webPass->expiry_time < Carbon::now()){
            $randomString = str::random(8);
            $webPass->pass = $randomString;
            $webPass->expiry_time = Carbon::now()->addSeconds(30);
            $webPass->update();
            Auth::logout();
            return redirect('/otp')->with('expiry_time', 'Your session has expired');
        }
        return $next($request);
    }
mqamar
  • 11
  • 4