Specify the api guard when using the helper
May 8, 2024
3
Level 4
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
Please or to participate in this conversation.