adonisjs / auth

Official Authentication package for AdonisJS
https://docs.adonisjs.com/guides/auth/introduction
MIT License
191 stars 65 forks source link

Switch database connection before auth.attempt #170

Closed swapnilnandgave closed 3 years ago

swapnilnandgave commented 3 years ago

How do i set db connection name while auth.attempt?

we have changing database connection on the fly as per request using Database.connection but while trying do auth.attempt then it uses default connection which is set in env

Is there any way to set connection before auth.attempt?

swapnilnandgave commented 3 years ago

Default connection is working as expected but I want to switch db connection before auth.attempt Can somebody help me with this? It is bit urgent.I have tried below but nothing works.

First tried this User.connection = connectionName - doesn't work

Then ctx.auth.config.provider.connection = connectionName - doesn't work

Then user.useConnection(connectionName) - doesn't work

Then in User.ts static get connection () { return 'mssql4'; } - doesn't work

Even I have tried by adding new guard and tried but it is taking default env connection instead of mentioned connection defined in guard list

auth.ts

api4: {
      driver: 'oat',
      tokenProvider: {
        type: 'api',
        driver: 'database',
        table: 'api_tokens',
        foreignKey: 'user_id',
      },

      provider: {
        driver: 'database',
        identifierKey: 'id',
        uids: ['email'],
        usersTable: 'users',
        connection: 'mssql4'
      },
    },

auth.ts in contract

In interface ProvidersList

dbuser: {
      implementation: DatabaseProviderContract<DatabaseProviderRow>,
      config: DatabaseProviderConfig,
    },

In interface GuardsList api4: { implementation: OATGuardContract<'dbuser', 'api'>, config: OATGuardConfig<'dbuser'>, },

Nothing works for me. Anything missing over here

thetutlage commented 3 years ago

Issue doesn't adhere to the guidelines of creating a proper issue.

  1. Make sure that you are only reporting bugs or submitting feature requests on Github.
  2. In case of feature requests, please be descriptive and explain how this feature helps a broader audience and not just you.

If you are not submitting a bug and neither a feature request, then please use the discussion threads

In any case, issues which are not descriptive enough will be closed. Please respect our time.