Search code examples
laravelshopify-appshopify-api

Route redirection is not working in 'verify.shopify' middleware in laravel shopify app with using "Kyon147/laravel-shopify" package


I am using Kyon147/laravel-shopify package for my laravel shopify app integration and I just found that in verify.shopify middleware custom routes are not working while I call the same routes outisde middleware and it's working fine.

I am using Kyon147/laravel-shopify package for my laravel shopify app integration and I just found that in verify.shopify middleware custom routes are not working while I call the same routes outisde middleware and it's working fine.

route::middleware(['verify.shopify'])->group(function () {
    // index page
    Route::get('/', [ConfigController::class, 'viewWelcome'])->name('home');

    // app - plan page
    Route::get('/plan', [ConfigController::class, 'viewPlans'])->name('plan');

});

Route::get('/privacy', [PagesController::class, 'privacyPolicyPage'])->name('pages.policy'); // contact support page

Here, /privacy route is completely working outside the middleware.

Package Name: Kyon147/Laravel-shopify


Solution

  • I have a solution for this issue, and here's an answer for the Kyon147\Laravel-Shopify package.

    If you are using the blade file then Replace Route() or URL() helpers to URL::tokenRoute() facades.

    For example:

    <a class="btn btn-sm py-3 w-sm-100 w-auto" href="{{ URL::tokenRoute('products') }}">Products </a>
    

    If you are using the controller file then Replace redirect() or redirect()->route() helpers to URL::tokenRoute() facades.

    public function home(Request $request)
    {
        return view('home');  // return home page
    }
    
    public function dashboard(Request $request)
    {
        return \Redirect::tokenRedirect('home');  // redirect to home route
    }
    

    This code is working for me