Hi I was working with laravel sanctum (laravel 9) and I wanted to use a token to access a route group that required authentication. I however use a distributed application architecture with laravel as back-end framework and an independent client. I wanted to access the following route group :
Route::group(['middleware' => ['auth:sanctum']], function() {
Route::get('/templates', [TemplateController::class, 'index']);
});
import axios from "axios"
const basePath = "http://localhost:8000/api/"
const token = localStorage.getItem('test_token')
const headers = {headers :{ Authorization: `Bearer ${token}` }};
axios.get(basePath+'templates',headers)
.then(resp => {console.log(resp)})
This however resulted in a status 401 with the following default unauthorized error :
Failed to load resource: the server responded with a status of 401 (Unauthorized)
Does anyone know how to send a token to laravel sanctum so the middleware can detect it? Thanks in advance.