router.beforeEach((to, from, next) => {
if (to.name !== 'Logon' && !localStorage.getItem('authToken')) {
next({ name: 'Logon' })
} else и тут мне надо сделать фетч запрос на сервер проверить токен и если токен верный то перекинуть меня дальше, и вот тут у меня и не получается ничего...Видимо так как после else должно идти только next()
})
router.beforeEach((to, from, next) => {
if (to.name !== 'Logon' && !localStorage.getItem('authToken')) {
next({ name: 'Logon' })
} else next()
})
router.beforeEach((to, from, next) => {
if (!localStorage.getItem('authToken')) {
next({ name: 'Logon' })
} else next()
})
Route::post('/users/create', [UserController::class, 'store']);
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
class HanldeRequest
{
public function handle($request, Closure $next)
{
return $next($request)
->header('Access-Control-Allow-Origin', '*')
->header('Access-Control-Allow-Credentials',true)
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
}
}