How to Redirect tenant to subdomain home page after user can login in public schema

Viewed 27

I have to redirect to home page without login in subdomain after login in public tenant That means suppose -

public domain is : logic.com

subdomain is : tenant1.logic.com I have tried to login to the public domain (logic.com/login) so now I have to redirect to the home page of the subdomain(tenant1.logic.com/home) Without subdomain login

def login_user(request):
    if request.method == 'GET':
        return render(request, 'users/login-user.html', {'form': AuthenticationForm()})
    else:
        user = authenticate(request, username=request.POST['email'], password=request.POST['password'])
        if user is None:
            return render(request, 'users/login-user.html', {'form': AuthenticationForm(), 'error': 'Username and '
                                                                                                    'password did not '
                                                                                                    'match'})
        else:
            client = Client.objects.filter(owner=user).first()
            with schema_context(client.schema_name):
                login(request, client.owner)
                host = request.META.get('HTTP_HOST', '')
                scheme_url = request.is_secure() and "https" or "http"
                url = f"{scheme_url}://{client.slug}.{host}"
                return HttpResponseRedirect(url)

What can I do if anyone has know about this?

Thanks in advance

Also I have added install app from setting

I am getting this error : django.contrib.sessions.exceptions.SessionInterrupted: The request's session was deleted before the request completed. The user may have logged out in a concurrent request, for example.

1 Answers

I think you just need to add:

SESSION_COOKIE_DOMAIN=".logic.com"

in your settings.py for allowing all subdomains for the session. More informations in django docs: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-SESSION_COOKIE_DOMAIN

Edit: i did not see your edit, so you have already set the settings opt and it does not work. Tenant_user seems to use the default django backend so it would be work with the settings. Have you replaced the backend ?

Related