Adonis Action Token create temporary token to perform specific actions like email validation, password recovery & more possibilities.
Works only for Adonis v5.
Action token is use to manage access (time-limited) for specific resource defined by action type. They are not intended to be used for authentication purposes.
The token works like opaque token (only string identifier, all useful data are stored directly on redis).
- Create action token
// create(type: string, ttl: int, data: string | undefined): string
const actionToken = await ActionToken.create('email-validation', 1800, { email: '[email protected]' })
// actionToken = 1608568833696DtHvtHx2DvxeTiHRLshXwhVvIlb34k8yHor1jKlqV5
- Validate token (middleware)
// verify(action: string, token: string): ActionToken
await ActionToken.verify('email-validation', actionToken)
- Get token data
// ActionToken(action: string, token: string): ActionToken
const token = new ActionToken('email-validation', token )
const data = token.data
- Delete token
// ActionToken(action: string, token: string): ActionToken
const token = new ActionToken('email-validation', token )
await token.delete()
The project elloow - api
use the action token concept (organisation creation with email link).