How to delete Iron Router history - meteor

I am using Iron router for meteor and want to create android mobile apps. I create login page that look like WhatsApp application. After user successfully login, i want to make sure that when user click back button,user will never go back to that page. Home page after login is the last page user will view if he keep click back button. So if user click two times back button in the homepage, the application will close.
I hope anyone understand my problem.
My problem is, the first time after user register, the android functionality to kill application after two times back click will not occur.Or can i replicate the two times back button function so if i am in my homepage(after login), and i click button two times, the application will close?

Iron:router has the option {replaceState: true} that you can use.
To accomplish this, all that you need to do is to change your Router.go('home') to Router.go('home', {}, {replaceState: true}) in your redirect hook after login.
With this when your use presses the back button, home will have replaced your login route in the history, and the user will not go to the login page.

EDIT: I just realised that's not exactly what you asked for, but it could help you somehow anyway. I'll try to replicate your case and will edit this post if I find a solution for your issue with exiting the application.
You could accomplish that by setting login page to be displayed only if user is not logged in.
Depends on your app structure you can use {{currentUser}} in html or Meteor.userId() in JS. One solution (the easy way) would be evaluating Meteor.userId() (true if user logged in) on login page route. If it turns out that user is already logged in, it redirects to home page for example.

Related

How to handle firebase authentication on vue

I’m working with a vuejs project and I’m using firebase oauth authentication.
I’ve already implemented the sign in with popup flow, and the auth state change event listener, it works pretty well.
The thing is, after I sign in, when I refresh/first load the application, as the auth session persists, there’s a time span between the app load and the auth state change is triggered, so even though I’m logged in, I see the login screen for a few seconds before the event is fired and I get redirected to the main page
For example
I open the application
As I’m not authenticated, I get redirected to /login
I see the login screen
I sign in using the google provider and the popup
I get redirected to the main page /
I refresh the page
I get redirected to /login
As I was already authenticated, the authStateChange event fires and I get redirected to the main page, but this happens after a couple seconds
There’s any way to handle that previous state to be able to show a “loading...” or something? I’ve been reading the docs but the only thing I found is using the event listener that I’m already using
Thank y’all in advance!
Okay y’all, this is the solution I came with:
There’s no way to know if an user will ve logged in until it gets actually logged in and the authStateChange event fires. So the best I could do is, when the user logs in into the application, I store a “EXPECT_LOGIN” value in localStorage, so if I reload the app, and that value it’s true i show a “Loggin in” message with a timeout of, say, 5 seconds. Here we have two possibilities:
The event is fired and the user is logged in automatically
The timeout is fulfilled and I set the “EXPECT_LOGIN” value to False, then I let the user login manually

Specflow test on login

I have a Specflow/Gherkin test to test an Asp.net application that involves logging into to perform an action using Selenium (and FireFox). Above my controller action I have the [Authorize] token and the site performs as I expect when manually testing. My login uses Forms Authentication.
My test goes as follows:
Navigate to Login page
Provide user and password
Click Login
Navigate to Create Product page (must be logged in)
Enter product detail
Save button
Check item is in database
What looks to be happening is steps 1-3 are fine. But when I execute Step 4, it is redirecting to the login page again. So Step 5 fails, as that isn't the page that is expected.
If I Start at Step 3 and login on the redirect, it works fine e.g.:
Navigate to Create Product page
Provide user and password
Click Login
Enter product detail
Save button
Check item is in database
Is there something specific I need to add to Selenium to make it save the session/login token?
When we're writing a BDD test either with Specflow, Cucumber or any other tool, we need to center our focus on what the end user needs to do to get the scenario done, in other words: the "As a user" perspective.
So in your scenario, as a user if he needs to navigate to loginPage, login and then navigate to createProductPage and login again, so be it! If that's true, write steps that would login again.
If not, on the other hand, if the user needs to login one single time, you don't need to store a session or anything else, I think in this case you have a bug in your application.
PS: if that wont work you can store a profile of your browser with the authentication token and use it, because when a browser gets instantiated it gets a clean browser profile.
OK so it transpires that the transition between steps 3 and 4 are happening too quick. So once I Login, i should verify the page title for example (as it redirects back to the Home page) and then proceed to the Create. Step 4 happens too quick to save the cookie/session.

ASP.Net - MVC 5 - log user off if user left a particular area

The goal:
I am trying to get the user to log off if they leave this area.
Area name: employer
if the user goes to the home page or anywhere else on the web and tries to log in or hits the back button I want the system to end the users session.
for example:
www.example.com/employer/dashboard - is protected and the user has to be logged in to access this area.
if the user goes to www.google.com and try to go back to www.example.com/employer/dashboard their session ends and they are redirected to the login page.
Some Questions:
Would it be a good idea to make an extend to the AuthorizeAttribute?
How would I log the user off?
How can I detect if the user leaves the area and comes back.
Should I make some sort of base controller that all of the other controllers inherit in the area so the area is protected?
Should the solution be server side?
any advice would help
For such purposes ASP.NET MVC authorization filters are used, which runs before any other filter.
the idea is to check if Path matches with Safe path then load area, otherwise don't authenticate and redirect to login. The tricky part is to control flow and not be trapped in page loop.
Check out this:
http://www.dotnetcurry.com/showarticle.aspx?ID=957
I will suggest to use window.onunload event and logout your user when this event occurs.

How can I stop user from navigating to the previous page

I am developing a simple email portal as my college assignment and I refer gmail for various features.Now when we sign into a gmail account and then if we hit the back button of the browser we somehow still remain on the inbox page.In my case after login if I press back button I comeback to the login page.Please suggest how can I achieve this.Also I am a newbie to ASP.NET so keep it detailed
Very simple. When loading the login page, check the user's current session state, and if they're already logged in, redirect them to their inbox.
The trick is to use javascript's "history.replace(...)" function:
http://www.hunlock.com/blogs/Mastering_The_Back_Button_With_Javascript
In essence, you remove previous history entries.

hit back in the browser

When i hit back in the browser the user is still logged in. can someone help please?
I'm assuming mean:
"After the user logs out, if they then press back in the browser the page says they are still logged in. How do I stop this?"
If so, what the user is seeing is the browsers cached version of the page - they are not actually still logged in, and if they were to browse elsewhere, then they would see that they are now logged out.
I often get around this by having the LoginStatus control have a LogoutAction of Redirect, and the LogoutPageUrl set to something like the homepage.
That is the correct behaviour for most web applications. Being logged in is a question of state, and does not rely on the page you are viewing.
If you want the back button to log the user out, then it would seem that it is a case of whichever page the previous one was, is where you want logged in users to be automatically logged out. It might be the case that the previous page (accessed through the back option) is the login page, where you would want logged in users to automatically be logged out.
To get a more accurate and more helpful answer, you should specify what behaviour you are expecting, and include details about the authentication system you are using (for example ASP.NET membership).

Resources