Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rhand's avatar
Level 6

Jetstream Inertia Ziggy route does not load frontend when not logged in

On loading a Ziggy / Jetstream route http://localhost:81/articles/8 - not logged in - frontend I get

TypeError: null is not an object (evaluating 'e.$page.props.user.name') — 

and a white screen. Route is

Route::get('/articles/{article}', ArticleShowController::class)->name('articles.show');

in web.php and not in a group with middleware. But it seems Jetstream / Inertia is still blocking the loading for content .

Here is the controller

<?php

namespace App\Http\Controllers;

use App\Models\Article;
use Illuminate\Http\Request;
use Inertia\Inertia;

class ArticleShowController extends Controller
{
    /**
     * Handle the incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function __invoke(Request $request, Article $article)
    {
        $article->load('user');

        return Inertia::render('Article/Show', compact('article'));
    }
}

How can I make that work?

0 likes
4 replies
vincent15000's avatar

If you are not connected, you can't have the name of the --- no --- connected user.

TypeError: null is not an object (evaluating 'e.$page.props.user.name')

What's the relationship with ziggy ?

1 like
rhand's avatar
Level 6

@vincent15000 well, Jetstream works with Inertia and Ziggy . Ziggy for routing. But guess the route used here a standard Laravel route then?

Main question is though how I can load single articles and articles overview frontend for visitors so non logged in users. Adding an article, editing an articles and loading a single article all work well when logged in. But want to display articles overview and single articles to the public.

1 like
rhand's avatar
Level 6

Using

<?php

namespace App\Http\Controllers;

use App\Models\Article;
use Illuminate\Http\Request;
use Inertia\Inertia;

class ArticleShowController extends Controller
{
    /**
     * Handle the incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function __invoke(Request $request, Article $article)
    {
       // $article->load('user');

        return Inertia::render('Article/Show', compact('article'));
    }
}

with $article->load('user'); commented out loading /articles sends me to login so it either has to do with Fortify but probably with Sanctum. The route is inside a group with middleware

<?php

use App\Http\Controllers\ArticleShowController;
use App\Http\Controllers\Dashboard\ArticleController;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Route;
use Inertia\Inertia;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return Inertia::render('Welcome', [
        'canLogin' => Route::has('login'),
        'canRegister' => Route::has('register'),
        'laravelVersion' => Application::VERSION,
        'phpVersion' => PHP_VERSION,
    ]);
});

Route::middleware(['auth:sanctum', 'verified'])->group(function () {
    Route::get('/dashboard', function () {
        return Inertia::render('Dashboard');
    })->name('dashboard');

    Route::resource('articles', ArticleController::class)->except('show');
});

Route::get('/articles/{article}', ArticleShowController::class)->name('articles.show');

However the url http://localhost:81/articles/9 still loads a white screen with same error

[Error] Unhandled Promise Rejection: TypeError: null is not an object (evaluating '_ctx.$page.props.user.name')
	logError (app.js:19641)
	handleError (app.js:19627)
	callWithErrorHandling (app.js:19581)
	flushJobs (app.js:19807)
	promiseReactionJob

So I need to somehow load routes publicly without the use of Sanctum / need to log in. And loading Show.vue somehow demands access to user it seems which is not granted.

1 like
rhand's avatar
Level 6

Using

<?php

namespace App\Http\Middleware;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Inertia\Middleware;

class HandleInertiaRequests extends Middleware
{
    /**
     * The root template that's loaded on the first page visit.
     *
     * @see https://inertiajs.com/server-side-setup#root-template
     * @var string
     */
    protected $rootView = 'app';

    /**
     * Determines the current asset version.
     *
     * @see https://inertiajs.com/asset-versioning
     * @param  \Illuminate\Http\Request  $request
     * @return string|null
     */
    public function version(Request $request)
    {
        return parent::version($request);
    }

    /**
     * Defines the props that are shared by default.
     *
     * @see https://inertiajs.com/shared-data
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function share(Request $request)
    {
        return array_merge(parent::share($request), [
            'user' => function () {
                return Auth::user() ? [
                    'id' => Auth::user()->id,
                    'name' => Auth::user()->name,
                    'email' => Auth::user()->email,  
                ] : null;
            },
        ]);
    }
}

for app/Http/Middleware/HandleInertiaRequests.php does not help either. Error remains.

1 like

Please or to participate in this conversation.