Ошибка при попытке создать токен JWT в API регистрации с использованием TypeScriptJavascript

Форум по Javascript
Ответить
Anonymous
 Ошибка при попытке создать токен JWT в API регистрации с использованием TypeScript

Сообщение Anonymous »

Code:
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:1077:36)
at Object.compile (C:\Users\aman8\Music\OMS-Project\OMS-backend\node_modules\ts-node\src\index.ts:1433:41)
at Module.m._compile (C:\Users\aman8\Music\OMS-Project\OMS-backend\node_modules\ts-node\src\index.ts:1617:30)
at node:internal/modules/cjs/loader:1895:10
at Object.require.extensions. [as .ts] (C:\Users\aman8\Music\OMS-Project\OMS-backend\node_modules\ts-node\src\index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:1465:32)
at Function._load (node:internal/modules/cjs/loader:1282:12)
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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Javascript»