adonisjs / auth

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

[V5] custom token table and field name #154

Closed rodrigorz closed 3 years ago

rodrigorz commented 3 years ago

Package version

@adonisjs/ace: ^6.0.0 @adonisjs/auth: ^4.3.1 @adonisjs/core: ^5.0.0-preview-rc @adonisjs/fold: ^6.0.0 @adonisjs/lucid: ^8.4.4

Node.js and npm version

Node: v12.18.3 npm: 6.14.6

Sample Code (to reproduce the issue)

My config/auth.ts

apiPlayer: {
      driver: 'oat',

      tokenProvider: {
        driver: 'database',
        table: 'player_tokens',
      },

      provider: {
        driver: 'lucid',
        identifierKey: 'id',
        uids: ['email'],
        model: Player,
      },
},

My contracts/auth.ts

  interface ProvidersList {
    player: {
      implementation: LucidProviderContract<typeof Player>,
      config: LucidProviderConfig<typeof Player>,
    },
  }

  interface GuardsList {
    apiPlayer: {
      implementation: OATGuardContract<'player', 'apiPlayer'>,
      config: OATGuardConfig<'player'>,
    },
  }

When a try to await auth.use('apiPlayer').attempt(email, password) i get this error:

insert into `player_tokens` (`created_at`, `expires_at`, `name`, `token`, `type`, `user_id`) values ('2020-10-10 14:15:27', NULL, 'Opaque Access Token', 'aa72d4c672f7d55f812dc4fd4c4bd68b0c018c4517e1c2257b4f86c6e2b84ad4', 'opaque_token', 1) - ER_BAD_FIELD_ERROR: Unknown column 'user_id' in 'field list'

I think all i need to do is use player_id instead of user_id, because the player_tokens table has a column player_id to reference players table.

How can i do that?

thetutlage commented 3 years ago

An existing PR already fixes this issue https://github.com/adonisjs/auth/pull/152. It will be released soon