how to prevent browser back to display login page after logged in in inertia js - laravel

How to prevent browser back to display login page after logged in in inertia js?
if you login to inertia demo CRM with this url :
Demo Inertia Js : https://demo.inertiajs.com/login
afetr loginning you can see login page by browser back again.
How can I solve it?
Thanks

If you have successfully logged in and you go back using history back, the only thing you are doing is previewing how the login page looked like. You aren't doing any request, just visiting your browser's history.
If you go back and refresh the page, you can see that you are now being redirected to the dashboard, which means that you did a request and the server detected you are logged in. As you are logged in, redirects you from /login (guest) to /dashboard (auth).
So in my opinion there is nothing to solve, you don't need to prevent browser back to display login page, you need a middleware to redirect you out from guest routes if you are logged in, that is it.
Docs:
History.back() - MDN docs
RedirectIfAuthenticated middleware - PingCRM

Reason login page is rendered even logged in is because login page rendering request is not sent to the server.
In the login form submission, you can put additional option to replace the page.
Browser back button will also replace the page and eventually, rendering request gets sent.
Inertia.post('/login', {
email: email,
password: password
}, {
replace: true
})

Related

Cannot login to backend - OctoberCMS

I'm trying to login into my localhosted OctoberCMS app. Everything works as well, except login to backend page. It stills redirect back to login of backend. When I add incorrect username/pass it works as expected (shows popup with message "invalid pass"). If I put correct data, it redirect back to login of backend. CSRF are disabled, link policy is detect and app_url is to http://localhost.

Middleware not working correctly after hitting browser 'go back' button for the first time Laravel

I have a login page and when the user enters their login and password correctly, I redirect them to a dashboard page. I am using Laravel guest middleware, so when a logged in user tries to go to login page, they get redirected to dashboard. Everything works fine, except when the user logs in and gets redirected to dashboard, if they hit the browser back button, the login page still shows. It only goes away after a refresh. How can I fix this problem?
Here's my routes:
Route::group( ['middleware' => 'guest' ],function()
{
Route::get('/', 'MainController#index');
Route::get('/loadLogin','MainController#loadLogin');
});
Surely this is because the browser caches the previous page? If the user attempted to POST or GET data to the page, the server would redirect them to loadLogin. The only thing the user is really seeing is the client-side code their browser saved, hence why the refresh fixes it.
JCode said check if the user is logged in the controller but controllers are not the place to be checking this.
Just check if user is logged in inside the index of MainController, if so - redirect to loadLogin.

react-redux passport-google react-router: success callback url redirects to '/' and redux state resets as page reloads

I'm building a page, where a user is allowed to fill in a form, but in order to submit it, he has to login. I am only allowing Google Login (passport-google-oauth2). After filling the form, if he has to submit it, and is not logged in, a dialogue box appears, where he is asked to login by Google.
After a successful login, the the google callback route, in I am redirecting him to '/' (homepage)
Callback route code
app.get('/auth/google/redirect',passport.authenticate('google'),
(req,res,next)=>{
res.redirect('/');
});
I am using react router to handle routing on client side
However, when he is redirected to '/' the page refreshes and my redux state resets. (My form data is stored in redux state and it becomes empty again).
Here are my 2 questions.
1) How can I redirect to a page after a successful login without the page refreshing (redux not losing it's state)
2) How can I know from which route I came from and redirect back to the same route? ie: if I called google login from '/form', then I should be redirected to '/form' and so on
Thanks in advancce!

JQuery Mobile - AJAX URL redirect breaks pageinit

TL;DR - AJAX URL redirect breaks 'pageinit' and any subsequent 'pageinit's that occur after the redirect
(see https://stackoverflow.com/a/14469041/2133816 for information on pageinit)
How to recover from this?
In Detail:
My mobile site has user accounts, so when a homepage button is selected that requires a user login it will first try to access the site in question...
m.smellyeggs.com/stuff?id=2497349187324&tr=454543522525
But once it is detected that the user has not logged in, the site reroutes the user to...
m.smellyeggs.com/login
Sadly, this event breaks functionality for all pageinit events:
$(document).on('pageinit', function(){
// things are done here
});
So after a redirect event occurs, no more pageinit events are detected, and unfortunately my data is loaded from the cache.
How can I recover from a "broken" pageinit, specifically occurring after an AJAX redirect.
Thank you!

Manage Login Redirection in Pyrocms

I need to manage login in such a way that it should redirect the control after successful login to the page which call login method in pyrocms.
By default it return control to Home Page. for example i want to go gallery page but it require user to be logged in so it will redirect control to the login page and now i want to redirect the control back to the gallery page once the user successful logged in.
Finally, i have come with the exact solution which is working correctly for me.
Whenever user try to view the gallery page(restricted page) which require user login, we have to only assign the URL where we want to redirect after successful login in $redirect_to in the controller method:
$this->session->set_userdata('redirect_to',$redirect_to);
Then it will automatically redirect the control to the desired page. Because in the users controller the login function is developed in such a way that:
$redirect_to = $this->input->post('redirect_to') ? $this->input->post('redirect_to') : $this->session->userdata('redirect_to');
Hopefully this will help you sometime

Resources