core
core copied to clipboard
While Token generation unknown column expires_at in field list
Package version
@adonisjs/core: "^5.1.6",
Node.js and npm version
Nodejs v15.0.0 and Npm 7.0.2
Sample Code (to reproduce the issue)
I am trying to generate api token in login api
steps
node ace configure @adonisjs/auth
> Select provider for finding users · lucid
> Select which guard you need for authentication (select using space) · api
> Enter model name to be used for authentication · UEU
> Create migration for the ueus table? (y/N) · true
> Select the provider for storing API tokens · database
> Create migration for the api_tokens table? (y/N) · true
node ace migration:run
Route.post('login', async ({ auth, request, response }) => {
const name = request.input('name')
const password = request.input('password')
// Lookup user manually
const user = await User.query().where('name', name).firstOrFail()
// Verify password
if (!(await Hash.verify(user.password, password))) {
return response.badRequest('Invalid credentials')
}
// Generate token
const token = await auth.use('api').generate(user, { expiresIn: '30mins'}
)
return token
})
Expected outcome
Token getting saved in database and send token in response
Actual outcome
insert into `api_tokens` (`created_at`, `expires_at`, `name`, `token`, `tyert intope`, `user_id`) values ('2021-05-07 16:41:12', '2021-05-07 16:41:12', 'er_id`) Opaque Access Token', '620c747319c0ea610cf20f12ed4dd9a4b6c21aa97960a257ken', '6719620ecbe9b7da6', 'api', 8) - ER_BAD_FIELD_ERROR: Unknown column 'expi, 8) - Eres_at' in 'field list'

it seems like the expires_at field not exist in your table