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

issue when need to authenticate (after a session expires) #89

Open
sdementen opened this issue Mar 23, 2020 · 2 comments
Open

issue when need to authenticate (after a session expires) #89

sdementen opened this issue Mar 23, 2020 · 2 comments
Labels
Q&A Questions and answers

Comments

@sdementen
Copy link

I have a case where my session expire after a modal form is active.

When I click on the action button, it calls the URL and it triggers the redirects to login and there it fails,

image

If I log directly on the page from the browser I see

image

My uneducated guess it that the request is done in xhr/ajax vs plain call.

Would you know how to fix this ?

@trco trco added the Q&A Questions and answers label Mar 25, 2020
@trco
Copy link
Owner

trco commented Mar 25, 2020

@sdementen Sorry, I don't understand exactly what you are asking. Please try to explain better and provide me an information how to replicate the issue.

@sdementen
Copy link
Author

sorry for not being clear, I try to rephrase based on your example application.
In your example, protect the create_book view behind a login_required

urlpatterns = [
    path('', views.Index.as_view(), name='index'),
    path('create/', login_required(views.BookCreateView.as_view()), name='create_book'),
    path('update/<int:pk>', views.BookUpdateView.as_view(), name='update_book'),
    path('read/<int:pk>', views.BookReadView.as_view(), name='read_book'),
    path('delete/<int:pk>', views.BookDeleteView.as_view(), name='delete_book'),
    path('signup/', views.SignUpView.as_view(), name='signup'),
    path('login/', views.CustomLoginView.as_view(), name='login'),
]

and add in the settings.py use as login URL an external page that would simulate a login page (i.e. do not use the modal login view you propose).
LOGIN_URL = "https://myaccount.google.com/"

As you are not logged in the website per default, any call to create_book will redirect to the login page (which is not BSModal compatible).
Hence, if you click on "Create book", you will see
image
and the modal form will not appear (nor an error message).

as there is a redirect due to login that do not accept "xhr" (and that cannot go in the Modal form anyway).

In my case, I have all the pages that are behind login_required so I do not have the problem except when the session expires. Then, the next call will be redirected to the login page. And if the next call is the one of BSModal, I have the problem described here above.

I am not sure of the kind of solution that could be used... :

  • if a redirect is detected when calling a modal form => redirect the full page ?
  • if an error happens when calling a modal form => display a customised error message ?

Is it clearer now ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Q&A Questions and answers
Projects
None yet
Development

No branches or pull requests

2 participants