adonisjs / auth

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

Auth.use().generate connection Issue #171

Closed swapnilnandgave closed 3 years ago

swapnilnandgave commented 3 years ago

Package version

node ace --version App version: 1.0.0 Framework version: 5.1.6 Assembler version: 5.1.1

Node.js and npm version

node - v14.15.4 npm - v6.14.10

Sample Code (to reproduce the issue)

I have added new guard with connection mssql4 but it is taking default env connection instead of mentioned connection defined in guard list

When I try to generate api token using api4 then it is connecting to default env db connection ctx.auth.use('api4').generate. I have attached below code snippet to better understand.

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'>, },

thetutlage commented 3 years ago

How do you verify that it is not using the correct connection?

swapnilnandgave commented 3 years ago

I had verified through below steps

  1. Default connection which used is mysql Which is localhost
  2. As you can see in above we have one more connection as mssql4 which is remote server DB
  3. I had stopped localhost connection
  4. When i tried to execute ctx.auth.use for api4 then throwing connect ECONNREFUSED 127.0.0.1:8889

Below is exact code snippet which is used. user record is getting from mssql4 connection using Database.connection('mssql4')

const token = await ctx.auth.use('api4').generate(user, {
                    expiresIn: '30days'
                })
thetutlage commented 3 years ago

Please share a repo to help reproduce the issue, as it works fine for me.

swapnilnandgave commented 3 years ago

Can you share your mail ID so I can share project directly to you?

thetutlage commented 3 years ago

I am looking for a simplified version that can help me reproduce the error. Going through your complete project is not possible for me

swapnilnandgave commented 3 years ago

I know you are busy but It would be great help for me

thetutlage commented 3 years ago

Closing since not actionable