Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

window.open causes logout #17

Open
bluefangs opened this issue Dec 3, 2018 · 4 comments
Open

window.open causes logout #17

bluefangs opened this issue Dec 3, 2018 · 4 comments

Comments

@bluefangs
Copy link

Hi,
I've tried this package for making sure the user session has been logged out when the tab is closed. The package seems to go one step further and logout the user even when the page is refreshed - which is ok for the most part. However, when I try to open a new tab with a certain url using window.open('some_custom_url_within_the_app', '_blank') OR window.open('some_custom_url_within_the_app', '_self') - it forces the user to be logged out - which doesn't seem to be nice.

What can be a workaround for this behaviour? Can there be a disable logout on page refresh as an option?

Thanks.

@tprzytula
Copy link
Owner

tprzytula commented Dec 3, 2018

Hi bluefangs,

This is an intended behaviour because the backend can't see a difference between opening a new tab or refreshing the current one. For both scenarios, it sees it as a brand new session.

What do you try to achieve by calling "window.open" ? If it's for routing purposes then I would suggest using routing package to avoid this issue (e.g. react router). Would it be possible for you?

If the reasoning is different as a workaround I could implement a method that you could call before opening the window, something like persistNextSession() but it doesn't seem too clean.

@bluefangs
Copy link
Author

bluefangs commented Dec 4, 2018

Hi tprzytula,

I have an application that gives the user an option to open a canvas either on the existing tab or on the new tab. While opening something on the new tab, Iron router does not seem to have any methods for this behaviour. Which is why I use window.open(url, '_blank'). There is also a couple of places where in I require to force refresh the current canvas when something loads - in which case, window.open(url, '_self') is being made use of. Using either of the two mechanisms logs out the user. Also, one cannot copy the url and physically paste it in a new tab either (more like a manual behaviour of window.open again) - which is what got me thinking if there is any mechanism to override refresh. persistNextSession() indeed sounds like a good fit - but probably for my usecase alone. I'm not sure how well it seem fit for the package as a whole.

Thanks.

@tprzytula
Copy link
Owner

tprzytula commented Dec 4, 2018

Hi @bluefangs

In the documentation, there is a section called "Best Practises".
The first example mentions adding return false; at the end of onClick.
Would that help you?

https://developer.mozilla.org/en-US/docs/Web/API/Window/open#Best_practices

If I understand correctly then logic like this:
<a href="#" onClick="window.open(targetPage); return false;">
should not cause a refresh on the current window

@bluefangs
Copy link
Author

@tprzytula ,

Apologies for a late turnaround. I tried the above approach but it doesn't seem to help in this case:

...
...
    'click #newCanvas': function() {
        window.open('/dashboard','_self');
        return false;
    },
...
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants