Auth Middleware reroutes to a wrong signin page auth.signin - laravel

I am using laravel 5.1 and i have applied an Auth middleware to a route, it works except my auth page is: /signin Not what it reroutes to /Auth.signin
I had deleted the default Auth folder and recreated my own inside app/Http/Controllers

Ok i solved it by going to the /Http/Middleware/Authenticate.php and changed this part of the code:
return redirect()->guest('auth.signin');
To:
return redirect()->guest('signin');

Related

Laravel Sanctum SPA Auth - Unauthenticated After Successfully Login

I have an application with Laravel and Vue.js for the separate folder which one is for the backend and another is the frontend and I have successfully configured all following the Laravel sanctum documentation and also protecting the route API and I am able to successfully log in and register but after successfully Login it's showing me "Unauthenticated " when I try to fetch the authenticated user. I am using localhost as a default. can anyone give me some suggestions
.env file I have also set it
SESSION_DRIVER=cookie
SESSION_DOMAIN=localhost
SANCTUM_STATEFUL_DOMAINS=localhost:8000
Thanks
Unfortunately, I have found the solution
#localhost
SESSION_DRIVER=cookie
SANCTUM_STATEFUL_DOMAINS=localhost:8080,127.0.0.1:8080,localhost:3000,127.0.0.1:3000
SESSION_DOMAIN=localhost
localhost:8080 for frontend server the port might be changing sometimes like localhost:8081 localhost:3000 so make sure you put the correct URL
#Live Server
SANCTUM_STATEFUL_DOMAINS=*.yourdomain.com
SESSION_DOMAIN=.yourdomain.com
I have also figure out sometimes I was right but the Laravel cache gives me the wrong result so you have to clean the Laravel cache and also browser cache. you can follow the below code to make a route function in web.php
Route::get('/clear', function() {
Artisan::call('cache:clear');
Artisan::call('config:clear');
Artisan::call('config:cache');
Artisan::call('view:clear');
return "Cleared!";
});
Hope it will works
Thanks

Route [x] not defined when using auth middleware

I am making a website with laravel but i am getting an error while using middleware auth. it says Route[x] not defined.
i am using laravel 5.8 please some one help me
The route you have written that has no named route so you need to specify name for that route like this
Route::get('x', function() {
//
})->name('x')->middleware('auth');
for more information you can check here https://laravel.com/docs/7.x/urls#urls-for-named-routes

Laravel Dusk auth issues with Laravel Passport

Can't test applications with Laravel Dusk if the app uses Laravel Passport for authentication. It's always 404 and if you stop the test with ->stop() it starts working.
The app is located: localhost:3000
and all requests are proxied to api.example.test
I've tried to authenticate the user inside the test:
$this->actingAs(User::find(1), 'api');
$browser->loginAs(User::find(1));
Passport::actingAs($this->user);
But still the same.
That's not the only problem, I think the main issue is also that I can't log in with Dusk by filling out the form and click "login"
$browser->visit('/login')
->type('#email', 'john#doe.com')
->type('#password', 'password')
->click('#login-button')
->waitForLocation('/');
But again, if you stop the test with ->stop() you can manually click the button and it will log you in.
Is Laravel Dusk useless if your app does not use basic auth?
Solved.
The problem was that my Dusk .env file had APP_URL=localhost:3000 where the front-end is located, but my APIs .env file had APP_URL=api.exmaple.com and that's why in my AuthController, I issued the token from env('APP_URL').'/oauth/token' <- which resulted in Dusk env to localhost:3000/oauth/token which is ofc 404
I changed that to env('API_URL') and added that value to my both .env files.

Laravel & PHPUnit: Getting 500 when unit testing "Passport" restricted route

I have a Laravel 5.3 app.
Inside my api.php file, there's a route for posting an answer within a poll.
Route::group(['middleware' => 'auth:api'], function () {
Route::post('/poll/answer', 'API\PollsController#createAnswer');
});
The route is part of a group, restricted by the auth:api middleware, using Laravel's Passport engine.
When calling this route from Postman or any other tool to test APIs, I get 401 which is ok because I'm not attaching the token.
But when unit testing this call using PHPUnit, it returns 500. I have no idea why.
$this->postJson('api/poll/answer');
I'm probably missing a configuration or setup instruction.
Any ideas?
The 500 error was occurring because I forgot to add an app key to the .env.testing file.
It got solved after adding that.

laravel 5.1 about Resetting Passwords

If I didn't log in , I can go to Route:http://localhost:8000/password/email,and show the view.
But, when I logged in,it go to Route:http://localhost:8000/home with an error
NotFoundHttpException in RouteCollection.php line 161:
I think it should also return view password.blade.php,but it did not
How to solve?
After a successful authentication the default action is to go to '/home', if there isn't the associated routes or views (controllers are provided by default) it causes the 'NotFoundHttpException' you mentioned.
If you haven't done already, you need to create the routes and views . The documentation mentions what you need to include.
If these exist already and you're wondering how to change the default behaviour of redirecting the user to '/home', you you can customize the post-authentication redirect location by defining a redirectPath property on the AuthController:
protected $redirectPath = '/dashboard';

Resources