stefanprokopdev / verify-apple-id-token

Verify the Apple id token on the server side.
MIT License
78 stars 15 forks source link

Error when import JwtPayload from jsonwebtoken #213

Open francozini2 opened 7 months ago

francozini2 commented 7 months ago

Hi! I installed the 3.0.1 version but I had this error:

node_modules/verify-apple-id-token/dist/lib/types.d.ts:1:15 - error TS2305: Module '"jsonwebtoken"' has no exported member 'JwtPayload'.

1 import type { JwtPayload } from "jsonwebtoken";
                ~~~~~~~~~~

Found 1 error in node_modules/verify-apple-id-token/dist/lib/types.d.ts:1

I have jsonwebtoken@9.0.2 and @types/jsonwebtoken@9.0.5

stefanprokopdev commented 7 months ago

Hello @francozini2 :wave:

Thanks for creating the issue! Can you please share with me part of your code? I would like to reproduce it :pray: I think we can start with package json and usage of the library. Thank you.

Btw you can also install the newest version 3.1.0.

francozini2 commented 7 months ago

Hi! @stefanprokopdev

The part of my code is this:

import verifyAppleToken from "verify-apple-id-token";

export const AppleService = {
    async verifyToken(token: string, nonce: string): Promise<Boolean> {
        try {
            const jwtClaims = await verifyAppleToken({
                idToken: token,
                clientId: "APPLE_API_CLIENT",
            })
            if (jwtClaims) {
                return true
            }
            return false
        } catch (error) {
            return false
        }
    },
}

and the package.json:

  "name": "",
  "version": "0.0.0",
  "author": "",
  "license": "UNLICENSED",
  "repository": {
    "type": "git",
    "url": ""
  },
  "main": "dist/index.js",
  "scripts": {
    "build": "tsc",
    "start": "node -r ts-node/register -r tsconfig-paths/register dist/src/server.js",
    "dev": "nodemon",
    "fix-lint": "prettier --config --write '**/**'",
    "check-lint": "prettier --config --check '**/**'",
    "ts-node-server": "ts-node src/server.ts",
    "prepare": "husky install"
  },
  "lint-staged": {
    "**/**": [
      "npx prettier --config --write '**/**'"
    ]
  },
  "jest": {
    "globals": {
      "__DEV__": true
    },
    "testEnvironment": "node",
    "testPathIgnorePatterns": [
      "/node_modules/"
    ]
  },
  "dependencies": {
    "@babel/generator": "7.7.4",
    "axios": "^0.27.2",
    "core-js": "3.4.7",
    "dotenv": "^8.2.0",
    "es6-promise": "4.2.8",
    "express": "^4.17.1",
    "http-status-codes": "1.4.0",
    "i18n": "^0.13.3",
    "jsonwebtoken": "^9.0.1",
    "moment": "^2.29.1",
    "moment-timezone": "^0.5.34",
    "tsconfig-paths": "^3.11.0",
    "validator": "^13.7.0",
    "winston": "^3.7.2",
    "verify-apple-id-token": "^3.1.0"
  },
  "devDependencies": {
    "@babel/cli": "7.7.4",
    "@babel/core": "^7.6.0",
    "@babel/helpers": "7.7.4",
    "@babel/node": "^7.15.8",
    "@babel/preset-env": "^7.7.4",
    "@babel/preset-react": "7.7.4",
    "@babel/preset-typescript": "7.7.4",
    "@babel/runtime": "7.12 .5",
    "@babel/runtime-corejs3": "7.7.5",
    "@types/jsonwebtoken": "^9.0.2",
    "axios-logger": "^2.6.2",
    "babel-core": "7.0.0-bridge.0",
    "babel-eslint": "10.0.3",
    "babel-jest": "24.9.0",
    "babel-loader": "8.0.6",
    "cross-env": "^6.0.3",
    "husky": "^7.0.0",
    "lint-staged": "^11.2.3",
    "nodemon": "^2.0.2",
    "prettier": "^2.4.1",
    "ts-node": "^10.0.0",
    "tslint-config-prettier": "^1.18.0",
    "typescript": "^4.4.3",
    "typescript-transform-paths": "^3.3.1"
  },
  "peerDependencies": {
    "@types/node": "^16.10.1"
  }
}

I want to tell you something before, I did some tests and it worked. I tried to change the way to import the verifyAppleToken

I changed import verifyAppleToken from "verify-apple-id-token"; to const verifyAppleToken = require("verify-apple-id-token").default; and works.

stefanprokopdev commented 6 months ago

Hey @francozini2 :wave: sorry for a very long delay :disappointed: I published a new version of the package v3.1.1. I made a package @types/jsonwebtoken a part of the production dependencies. So there shouldnt be a problem anymore because now its part of the package. Can you please let me know if its ok now and resolve the issue?

Thank you so much and sorry again. Btw wish you a happy new year :tada: