javapostgresqlmulti-tenantmicronautmicronaut-data

How to implement schema based multitenancy with micronaut


I'm starting to build a new webapp, it currently has an AuthenticationProvider which checks a user and password match what's in a database table. Its session based.

Currently micronaut just seems to use the public schema (I'm on postgres).

I've tried enabling a subdomain tenant resolver in my application.yml:

  data:
    multi-tenancy:
      mode: SCHEMA
      tenantresolver:
        subdomain:
          enabled: true

But I can't tell that it's doing anything. If I visit subdomain.localhost to test it a session cookie seems to appear tied to that subdomain, but any user from the public schema can authenticate against it. I assume my AuthenticationProvider needs to become tenant aware somehow?

If I then have another tenant sign up, who isn't authenticated at the point of registering, how would a schema get populated for them using micronaut data before they come to authenticate? Thanks.


Solution

  • In case it helps anyone else, I had two issues: