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

monstajamss's avatar

Problem with Laravel Sanctum

I have my api using laravel sanctum api for auth and in my api routes i have this

Route::get('/blog/{id}', BlogController::class);

and in my controller i have this

public function __invoke(Request $request)
{
   $blog = Blog::where('id', $request->id)->first()

	return response->json([
		'blog' => $blog
		'user' => $request->user()
	]);
}

The problem is that i do not know why the user is null in my nextjs application even though i have logged in.

also if i add sanctum auth middleware to the route i am not able to access the page in my nextjs application.

any help to solve this will be appreciated

Note: i have also done this auth()->user() and auth()->id() still null

0 likes
3 replies

Please or to participate in this conversation.