0

Getting the following error when i am trying to sign in with my jwt.

No overload matches this call.
 Overload 1 of 5, '(payload: string | object | Buffer<ArrayBufferLike>, 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<ArrayBufferLike>, secretOrPrivateKey: Buffer<ArrayBufferLike> | Secret | PrivateKeyInput | 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<ArrayBufferLike>, secretOrPrivateKey: Buffer<ArrayBufferLike> | Secret | PrivateKeyInput | JsonWebKeyInput, callback: SignCallback): void', gave the following error.
   Object literal may only specify known properties, and 'expiresIn' does not exist in type 'SignCallback'.

I read somewhere this is just typescript being dumb. and to use exclamation that the token is there. TS doesnt need to check, but to no avail.

What causes this error? How to fix it?

My config file is the following:

import dotenv from "dotenv";

dotenv.config();

const config: Config = {
  port: Number(process.env.PORT) || 3000,
  nodeEnv: process.env.NODE_ENV || "development",
  jwt: {
    accessSecret: process.env.JWT_ACCESS_SECRET!,
    refreshSecret: process.env.JWT_REFRESH_SECRET!,
    accessExpiry: "45m",
    refreshExpiry: "7d",
  },
};
export default config;

interface Config {
  port: Number;
  nodeEnv: string;
  jwt: jwtConfig;
}
interface jwtConfig {
  accessSecret: string;
  refreshSecret: string;
  accessExpiry: string;
  refreshExpiry: string;
}

and jwt code the following :

import jwt from "jsonwebtoken";
import config from "../config/config";

export const generateAccessToken = (userId: string): string => {
  return jwt.sign(
    {
      id: userId,
    },
    config.jwt.accessSecret,
    {
      expiresIn: config.jwt.accessExpiry,
    }
  );
};
1
  • IIRC, the problem is the property accessExpiry: string; of your argument. Check how the property is typed exactly in SignOptions. Commented Sep 27 at 21:07

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.