How to auto logout when goes to special url in laravel - php

In laravel, now I hope to know this problem.
I try to reset password in logout status and the problem is it's redirect automatically to dashboard page if I logged in already.
So I hope to know how to logout and goes to special url such as reset password url from my received mail.
Please help me!

Use Laravel Auth vendor. https://laravel.com/docs/5.1/authentication. After this in route file put all routes under authentication where you want user to be logged in.

For laravel 5+ :
create a middleware for your route and check your access condition in this middleware, if your route passes the condition then it will show your desired page.

Related

Laravel middleware Password Confirm change password_timeout

I was using this middleware:
Route::get('/{id}/edit',[PostController::class,'edit'])->name('post.edit')->middleware('password.confirm');
of laravel fortify so that it asks me for the password before accessing a route, but this depends on
'password_timeout'=>10800 in auth.php, so I need it to ask me for password whenever the route calls, try to set the value to 'password_timeout'=>1, but it is no longer possible to submit the form, it no longer returns Request validations from the controller. You could guide me to solve this problem. Thanks!

Custom api authentication in laravel

I am trying to make authentication based on API in laravel. Here is my process flow. First of all, I get data from API. If it is valid then I keep true value in the session. Through middleware, I check every route if it is authenticated or not. Am I on right track?
Session::put('authenticated', true);
session::get('authenticated');
Should I add anything to make it more efficient? Here the problem is I can not handle /login route. After successful login, it can be the visit the login page. Also I can't get session value in LoginController function __construct() . Thanks in advance. I am using laravel 5.5

How to use register auth in laravel

Good day,
I'll need some assistance with my laravel application.
So i'm routing to a page with some data and I used the auth middleware and so before it routes to that page redirects to the login page if user is not logged in which is fine. After login it proceeds to the route specified. But now when I try to register instead it doesn't proceed to that route but only back to home page. Is there another middleware that handles that?
Here's my route.
Route::get('/myroute', 'MyController#method')->middleware('auth')->name('somename');
I'll appreciate your assistance.
Thanks

Why does Laravel redirect me to the login page even though im still logged in?

I used php artisan make:auth in my laravel project to automatically create my login and registration pages.
Even though I'm still logged in when I leave my page for a few minutes and then go back to my laravel project page it redirects to the login page.
I know i'm logged in because I can see it on the upper part of the login page if user wasn't logged in it would display two buttons login and register and if user was already logged in it would just display my username which it did and also the fact that I can go to my dashboard page by just manually typing it in the url which shouldn't be allowed if user wasn't logged in :(
How can I fix this?
Assuming that you have a route of your dashboard
Route::route('/home', 'HomeController#index')->middleware('auth');
You just need to use auth middleware in order to add page visits restrictions.
You may check more authentication detail here https://laravel.com/docs/5.8/authentication

Laravel 5: when logged in entering URL, Laravel redirects to /home

I am building login functionality (rather say using it) and when I enter manualy
Route::get('/offers', 'OfferController#index'), I get redirected to /home.
Before login functionality my route was working just normal.
How could I solve this?
The reason you're getting the redirect is because you are using guest middleware on /offers route.
The purpose of the guest middleware (which uses RedirectIfAuthenticated class) is to redirect authenticated users out from pages that should be accessible only for guests, e.g. login form or registration page. Hence the middleware name guest. The middleware checks if user is authenticated and redirects authenticated users to /home which is exactly what you are experiencing.
You can see the code of the middleware here: https://github.com/laravel/laravel/blob/master/app/Http/Middleware/RedirectIfAuthenticated.php. The whole logic happens in its handle() method.

Categories