Hello,
I’m looking to hash the user’s password on the frontend of my app and verify the hashed password on the backend. When I try to extend the auth.register method, I get the error RangeError: Maximum call stack size exceeded
. Any help is appreciated. Thanks in advance! Here’s my code:
plugin.controllers.auth.register = (ctx) => {
// verify hashed password
return plugin.controllers.auth.register(ctx); // should I be returning something else?
}
Have you tried the lifecycle hook?
i believe the right choice for your use-case is to use the lifecycle hook beforeCreate
import { createHash } from 'node:crypto'
module.exports = {
async beforeCreate(obj) {
let { params } = obj // attributes model, state
const password = obj.data.PASSWORD_FIELD // Original value from request
// Overide the value with hashed / encrypted value
params.data.PASSWORD_FIELD = createHash('md5').update(password).digest('hex')
}
}
You can read more about it here Understanding the different types/categories of Strapi Hooks
everything in passwords fields are automaticly hashed as soon as they are added to the backend