Support the ongoing development of Laravel.io →
posted 2 years ago
Routing
Last updated by @tvbeek 2 years ago.
0
moderator

Hello @hihi25

Here you open a closure for a route but also try to register more routes.

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
    Route::post('usuario/pruebas','UserController@pruebas');
Route::get('/register','UserController@register');
Route::post('/login','UserController@login');
});

If that isn't a copy past error you could change it in:

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});

Route::post('usuario/pruebas','UserController@pruebas');
Route::get('/register','UserController@register');
Route::post('/login','UserController@login');

Else my first question is: What is the url you did test?

By default the api route file is prefixed by /api, that means your login url in this file is: yourdomain.tld/api/login

Sidenote: I placed your code in a code block to make it more readable on this site :)

faisal liked this reply

1

The middleware('auth:api') tests whether a user is already logged in, and if they are, then they allow access to the routes, you need to remove the register and login routes from that middleware. You could even make your own custom middleware, that protects these routes from users that are already logged in.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

John Dereck hihi25 Joined 8 Apr 2022

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.