VikhyatSharma17 / srms

0 stars 0 forks source link

Admin and normal user session overlaps and cannot be opened in the same browser session #3

Open VikhyatSharma17 opened 2 months ago

VikhyatSharma17 commented 2 months ago

When an admin session is logged in to the Django administrator dashboard and they try to open the application's homepage, the admin user shows as already logged in on the normal user application even though no login has happened.

HarshAgrawal1 commented 2 months ago

Log out admin users on the normal user site: You can enforce separate logins by automatically logging out the admin user when they access the normal user-facing application.

In your views.py or a middleware:

from django.contrib.auth import logout from django.urls import reverse

def user_homepage_view(request): if request.user.is_staff and not request.path.startswith(reverse('admin:index')): logout(request) # Logs out the admin user in the normal user session

Continue rendering the homepage