jwt регистрация выдает ошибку cdz
npm run dev
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
> server@1.0.0 dev
> nodemon index.js
[nodemon] 3.1.11
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,cjs,json
[nodemon] starting `node index.js`
[dotenv@17.2.3] injecting env (8) from .env -- tip: ✅ audit secrets and track compliance:
https://dotenvx.com/ops
C:\jwt\server\service\user-service.js:3
const uuid=require('uuid');
^
Error [ERR_REQUIRE_ESM]: require() of ES Module C:\jwt\server\node_modules\uuid\dist-node\index.js from C:\jwt\server\service\user-service.js not supported.
Instead change the require of index.js in C:\jwt\server\service\user-service.js to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (C:\jwt\server\service\user-service.js:3:12)
at Object.<anonymous> (C:\jwt\server\controllers\user-controller.js:1:19)
at Object.<anonymous> (C:\jwt\server\router\index.js:2:22)
at Object.<anonymous> (C:\jwt\server\index.js:7:15) {
code: 'ERR_REQUIRE_ESM'
}
[nodemon] app crashed - waiting for file changes before starting...
во т код uzser-service
const {UserSchema} = require('../models/models');
const bcrypt=require('bcrypt');
const uuid=require('uuid');
const mailService=require('./mail-service');
const tokenService=require('./token-service');
const UserDto=require('../dtos/user-dto');
class UserService {
async registration(email,password){
const candidate = await UserSchema.findOne({where: {email}});
if(candidate){
throw new Error(`Пользователь с почтовым адресом ${email} уже существует`);
}
const hashPassword = await bcrypt.hash(password, 5)
const activationLink=uuid.v4();
const user = await UserSchema.create({email,password: hashPassword,activationLink,role:'user'});
await mailService.sendActivationMail(email,activationLink);
const userDto=new UserDto(user);
const tokens=tokenService.generateTokens({...userDto});
await tokenService.saveToken(userDto.id,tokens.refreshToken);
return{
...tokens,
user:userDto
}
}
}
module.exports=new UserService();