birdietorerik's avatar

birdietorerik started a new conversation+100 XP

1mo ago

Hi! Making a Laravel application using Laravel 12.x and Vue3 Have big problem with -> Route::middleware('auth:sanctum')

api.php

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Api\AuthController;
use App\Http\Controllers\Api\ChurchController;
use Illuminate\Support\Facades\Auth;
use Laravel\Sanctum\PersonalAccessToken;
use App\Models\User;
use Illuminate\Http\Request;


Route::post('/register', [AuthController::class, 'register']);
Route::post('/login', [AuthController::class, 'login']);

Route::middleware('auth:sanctum')->apiResource('churches', ChurchController::class);

Route::middleware('auth:sanctum')->get('/me', function () {
    return response()->json([
        'user' => auth()->user()
    ]);
});

Route::get('/ping', function () {
    return ['status' => 'API works'];
});

Dashboard.vue

Login.vue

Problem:

After Login, it call Dashboard

But when /api/me is executed the server shut down

Get this error in console


Login.vue:37 [Vue warn]: Unhandled error during execution of mounted hook 
  at <Dashboard onVnodeUnmounted=fn<onVnodeUnmounted> ref=Ref< 
Proxy(Object) {__v_skip: true}
 > > 
  at <RouterView> 
  at <App>

Dashboard.vue:33 
 GET http://127.0.0.1:8000/api/me net::ERR_EMPTY_RESPONSE
favicon.ico:1 
 GET http://127.0.0.1:8000/favicon.ico net::ERR_CONNECTION_RESET
axios.js?v=bbf5963d:1669 Uncaught (in promise) AxiosError: Network Error
    at async newFunction (Dashboard.vue:33:16)
    at async Dashboard.vue:29:17

Please help