Support the ongoing development of Laravel.io →
posted 7 months ago
Routing
Last updated by @tvbeek 7 months 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[email protected]');
Route::get('/register','[email protected]');
Route::post('/login','[email protected]');
});

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','[email protected]');
Route::get('/register','[email protected]');
Route::post('/login','[email protected]');

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 :)

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!

LoadForge

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.

© 2022 Laravel.io - All rights reserved.