django-tenant-users: Unable to successfully login to django in any of public/other tenant
Read me or sample code never guided the exact format/order of instructions for tenant creations so I am trying mine according to given guidelines to create tenants with code in one of my shared app view
Created public tenant
public_owner = "owner@local" create_public_tenant("localhost", public_owner) tenant_admin_email = "admin@local" TenantUser.objects.create_superuser('123', tenant_admin_email)
Created my tenant
tenant_admin_email = "admin@" + tenant_name TenantUser.objects.create_superuser('123', tenant_admin_email) provision_tenant(tenant_name, tenant_name, tenant_admin_email)
It does all => creates tenant with schema and both the super users as well
But access to admin panel on public never succeeds (even login gets the user) with zero message And in tenants it always gives message as “Please enter the correct Email Address and password”
My settings are as ` MIDDLEWARE = ( ‘tenant_tutorial.middleware.TenantTutorialMiddleware’, ‘django.middleware.common.CommonMiddleware’, ‘django.contrib.sessions.middleware.SessionMiddleware’, ‘django.middleware.csrf.CsrfViewMiddleware’, ‘django.contrib.auth.middleware.AuthenticationMiddleware’, ‘django.contrib.messages.middleware.MessageMiddleware’, # Uncomment the next line for simple clickjacking protection: # ‘django.middleware.clickjacking.XFrameOptionsMiddleware’, )
TENANT_MODEL = “customers.Client” # app.Model TENANT_DOMAIN_MODEL = “customers.Domain” # app.Model TENANT_USERS_DOMAIN = “localhost” AUTH_USER_MODEL = ‘users.TenantUser’ AUTHENTICATION_BACKENDS = ( ‘tenant_users.permissions.backend.UserBackend’, ) SESSION_COOKIE_DOMAIN = ‘.’ + TENANT_USERS_DOMAIN
SHARED_APPS = ( ‘django_tenants’, ‘django.contrib.admin’, ‘django.contrib.admin’, ‘django.contrib.auth’, ‘django.contrib.contenttypes’, ‘django.contrib.sessions’, ‘django.contrib.messages’, ‘django.contrib.staticfiles’, ‘tenant_users.permissions’, ‘tenant_users.tenants’, ‘customers’, # you must list the app where your tenant model resides in ‘users’, )
TENANT_APPS = ( ‘django.contrib.admin’, ‘django.contrib.auth’, ‘django.contrib.contenttypes’, ‘tenant_users.permissions’, ‘django.contrib.admin’, ‘django.contrib.sessions’, ‘django.contrib.messages’, ‘tenant_only’, )
INSTALLED_APPS = list(set(TENANT_APPS + SHARED_APPS)) `
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15
For me, the issue was:
SESSION_COOKIE_DOMAIN = ".localhost".It’s not a django-tenant-users issue, or a django-tenant issue. It’s just a web issue - you can’t have
.localhostas a valid session domain. https://code.djangoproject.com/ticket/10560Removing this solved, but now I can’t stay logged in across domains. But that’s probably outside the scope here.
Also, @JupiterThreads - I wouldn’t call
UserTenantPermissions.objects.create()directly as there’s an extra step to link the User to the Tenant. Instead, you can do:Yeah after you’ve created that user that is a system user you don’t really interact with again, it creates a random password for it. You need to create another user with super user permissions and use that user.
So after you’ve created your new user in the public tenant now create a permission for that user like so:
UserTenantPermissions.objects.create(profile=new_user, is_staff=True, is_superuser=True)Then you should be able to login to admin.I’m having a very similar problem. My second tenant is setup at
test.localhost:5000and I can viewtest.localhost:500/adminjust fine, but when logging in, it keeps saying I need a staff or active account.I then tried to login to the base
localhost:5000/adminand was met with an error that says:This is after trying to login to
test.localhost:5000with that email - so I’m logging in, but somehow don’t have permissions to view the admin?