const newUser = new User({
username,
email,
password: passwordHash,
organization: null,
designation: null,
role: "user",
});
await newUser.save();
const token = jwt.sign(
{
id: newUser.id,
username: newUser.username,
email,
organization: null,
designation: null,
role: "user",
},
JWT_SECRET,
{
expiresIn: JWT_EXPIRES_IN,
}
);
};
< /code>
Error:
return new TSError(diagnosticText, diagnosticCodes, diagnostics);
^
TSError: ⨯ Unable to compile TypeScript:
src/controllers/auth.controller.ts:33:21 - error TS2769: No overload matches this call.
Overload 1 of 5, '(payload: string | object | Buffer, secretOrPrivateKey: null, options?: (SignOptions & { algorithm: "none"; }) | undefined): string', gave the following error.
Argument of type 'string' is not assignable to parameter of type 'null'.
Overload 2 of 5, '(payload: string | object | Buffer, secretOrPrivateKey: Secret | PrivateKeyInput | Buffer | JsonWebKeyInput, options?: SignOptions | undefined): string', gave the following error.
Type 'string' is not assignable to type 'number | StringValue | undefined'.
Overload 3 of 5, '(payload: string | object | Buffer, secretOrPrivateKey: Secret | PrivateKeyInput | Buffer | JsonWebKeyInput, callback: SignCallback):
void', gave the following error.
Object literal may only specify known properties, and 'expiresIn' does not exist in type 'SignCallback'.
33 const token = jwt.sign(
~~~~
at createTSError (C:\Users\aman8\Music\OMS-Project\OMS-backend\node_modules\ts-node\src\index.ts:859:12)
at reportTSError (C:\Users\aman8\Music\OMS-Project\OMS-backend\node_modules\ts-node\src\index.ts:863:19)
at getOutput (C:\Users\aman8\Music\OMS-Project\OMS-backend\node_modules\ts-node\src\index.ts
at Object.compile (C:\Users\aman8\Music\OMS-Project\OMS-backend\node_modules\ts-node\src\index.ts
at Module.m._compile (C:\Users\aman8\Music\OMS-Project\OMS-backend\node_modules\ts-node\src\index.ts
at node:internal/modules/cjs/loader
at Object.require.extensions. [as .ts] (C:\Users\aman8\Music\OMS-Project\OMS-backend\node_modules\ts-node\src\index.ts
at Module.load (node:internal/modules/cjs/loader
at Function._load (node:internal/modules/cjs/loader
at TracingChannel.traceSync (node:diagnostics_channel:322:14) {
diagnosticCodes: [ 2769 ]
}
I was trying to create a jwt token using jsonwebtoken library using typescript but getting error.
Подробнее здесь: https://stackoverflow.com/questions/797 ... typescript
Мобильная версия