I did all these steps, but when i am trying to get user data i get Unauthenticated error routes/api.php
Route::middleware('auth:sanctum')->get('/user', function (Request $request) { return $request->user(); });
home.vue
<script> import axios from "axios"; axios.defaults.withCredentials = true; axios.defaults.baseURL = "http://localhost:8000/"; export default { mounted(){ axios.get("/api/user").then((response)=>{ console.log(response); }) } } </script>
I do not know if i did any thing wrong ?
Happening the same to me :(
I solved it , in your Providers/RouteServiceProvider.php, change the mapApiRoutes function from middleware(['api']) to middleware(['web'])
protected function mapApiRoutes() { Route::prefix('api') ->middleware('web') ->namespace($this->namespace) ->group(base_path('routes/api.php')); }
Hope this helping you.
Great work, please i will like to have a little chat with u man
This is not a good solution,
The solution is to set value for
SANCTUM_STATEFUL_DOMAINS='127.0.0.1:3000'
in the .env file
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I did all these steps, but when i am trying to get user data i get Unauthenticated error
routes/api.php
home.vue
I do not know if i did any thing wrong ?
Happening the same to me :(
I solved it , in your Providers/RouteServiceProvider.php, change the mapApiRoutes function from middleware(['api']) to middleware(['web'])
Hope this helping you.
Great work, please i will like to have a little chat with u man
This is not a good solution,
The solution is to set value for
in the .env file