Error: Cannot find module 'phc-argon2' Adonis Js
Asked Answered
M

2

5

Hi everybody I try use hash in password model but if i try save a new user adonis send me this error :

Error: Cannot find module 'phc-argon2'

I find in official documentation of adonis but i not found some solution...

this is my model :

import { DateTime } from 'luxon'
import { BaseModel, column, beforeSave, hasOne, HasOne } from '@ioc:Adonis/Lucid/Orm'
import Hash from '@ioc:Adonis/Core/Hash'
import Profile from 'App/Models/Profile'
import Myvericode from 'App/Models/Myvericode'

export default class User extends BaseModel {
  @column({ isPrimary: true })
  public id: number

  @column.dateTime({ autoCreate: true })
  public createdAt: DateTime

  @column.dateTime({ autoCreate: true, autoUpdate: true })
  public updatedAt: DateTime

  @column()
  public name : string
  
  @column()
  public username : string
  
  @column({ serializeAs: null })
  public password : string

  @column()
  public phonenumber:string

  @column()
  public email : string
  
  @column()
  public isverifiedemail : number

  @hasOne(() => Profile)
  public profile: HasOne<typeof Profile>

  @hasOne(() => Myvericode)
  public vericode: HasOne<typeof Myvericode>

  @beforeSave()
  public static async hashPassword (user: User) {
    if (user.$dirty.password) {
      user.password = await Hash.hash(user.password)
    }
  }

}
I try npm i phc-argon2 and not work I using Linux operative system, thanks for de answers
Miyokomizar answered 17/9, 2020 at 20:30 Comment(2)
can you please share your package.jsonKoenraad
You need to make sure to restart the sever when done. I did have the same issue did npm install and restart now all work.Diplopod
C
15

In config/hash.ts has the steps of installation of encryptor who you want to use. Here you can set your driver: default: Env.get('HASH_DRIVER', 'bcrypt') then you can simply install the required driver who wanted

for argon2 npm install phc-argon2

for bcrypt npm install phc-bcrypt

is had worked for me

Chrono answered 5/1, 2021 at 15:45 Comment(0)
T
3

There is note for breaking change in the docs:

Earlier the argon2 and bcrypt drivers were relying on the following packages.

@phc/argon2
@phc/bcrypt

However, these packages are not actively maintained and had some security vulnerabilities. We have forked and published them as phc-bcrypt and phc-argon2. So make sure to remove old dependencies from your application in favor of the new ones.

more here: https://preview.adonisjs.com/releases/core/preview-rc-1_7/#hash

Kindly check for your adonis 5(specifically the core and auth) version if you're affected

Toiletry answered 21/9, 2020 at 5:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.