Laravel 8 E-Commerce - Solution for Admin Route Not Working After Stripe Integration

In this video, we will explore the solution for the admin route not working after Stripe integration.

Let's first understand the problem and then find a solution.

First, let's replicate the issue.

Switch to your browser and log in with user credentials.

Enter your email ID and password, and then click on login.

Now, open the dashboard, and you can see that it's working as expected.

Next, log out from the dashboard.

Then, log in with admin credentials, and enter the admin email ID and password.

You can see that the admin has been logged in successfully.

However, when you click on any admin menu, you are redirected to the login page.

This issue occurred after the Stripe installation, as it was working well before the Stripe payment gateway integration.

The reason for this problem is that when we run the `composer update` command to update packages, it updates all packages and replaces existing files with new ones.

As a result, the code written for admin authentication was removed from the `AttemptToAuthenticate.php` file in the vendor directory.

Now, let's find a solution to this problem.

Open the `AuthAdmin.php` middleware file and add the following code:


<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;

class AuthAdmin
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if(Auth::check())
{
if(Auth::user()->utype === 'ADM')
{
return $next($request);
}
else
{
session()->flush();
return redirect()->route('login');
}
}
else
{
session()->flush();
return redirect()->route('login');
}
}
}

Now its done so save it and lets check it.

So switch to browser and refresh the page.

Enter the admin email and password and click on login.

Alright now lets access the admin page.

And you can see here its working good now.

So in this way you can solve this problem.