Error: Cannot find module '../utils/appleAuth' on npm start

628 views Asked by At

here is the imports that I am using currently to implement apple auth on the backend

const Joi = require('joi')
const logger = require('../common/logger')
const errors = require('../common/errors')
const helper = require('../common/helper')
const models = require('../models')
const _ = require('lodash')
const jwt = require('jsonwebtoken')
const ms = require('ms')
const constants = require('../../app-constants')
const userService = require('./UserService')
const adminCommonService = require('./admin/AdminCommonService')
const User = models.User
const VerificationCode = models.VerificationCode
const fs = require('fs');
const AppleAuth = require('apple-auth');
const config = fs.readFileSync("./config/config");
const auth = new AppleAuth(config, 'config/apple/authkey.p8')



/**apple auth 
*/
const config = {
client_id: 'YOUR APP ID',
team_id: 'ZUU8485r88T',
redirect_uri: '', // Leave it blank
key_id: 'YOUR KEY ID',
scope: 'name%20email',
};
const appleAuth = new AppleAuth(
config,
fs.readFileSync('assets/apple/AuthKey_HVC8C93672.p8').toString(),
'text'
);

export const appleAuth = async (req: Request, res: Response){
 const { token: appleToken } = req.body;
try {
//retrieve apple Data from AccessToken
const apple = await AppleAuth.accessToken(appleToken)
const appleData = jwt.decode(apple.id_token);
//get apple Id
const{sub:appleID}=appleData;
//count the number of connections of user
const user = await User.findOneAndUpdate(
  {appleId},
  { $inc: { nbOfConnections: 1 } },   
  {upsert: true, new:true,userFindAndModify: false}
   );
   return res.status(200).json({user});
  } catch (err) {
    return res.status(500).json({message:err.message || err});
  }
};

and here is what my package.json looks like:

main": "app.js",
"scripts": {
"start": "node app.js",
"lint": "standard",
"lint:fix": "standard --fix",
"clear-db": "node src/clear-db.js",
"test-data": "node src/test-data.js"
},
 "author": "TCSCODER",
 "license": "none",
 "devDependencies": {
"standard": "^12.0.1"
 },
 "dependencies": {
"adm-zip": "^0.4.14",
"apple-auth": "^1.0.6",
"aws-sdk": "^2.636.0",
"axios": "^0.19.2",
"bcryptjs": "^2.4.3",
"bluebird": "^3.7.2",
"body-parser": "^1.15.1",
"bootstrap": "^4.5.2",
"config": "^3.0.0",
"core-util-is": "^1.0.2",
"cors": "^2.7.1",
"credit-card-type": "^8.3.0",
"express": "^4.14.0",
"get-parameter-names": "^0.3.0",
"googleapis": "^59.0.0",
"http-status-codes": "^1.4.0",
"joi": "^14.3.1",
"json-diff": "^0.5.4",
"json2csv": "^5.0.1",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.15",
"mime-types": "^2.1.27",
"moment": "^2.24.0",
"moment-range": "^4.0.2",
"moment-timezone": "^0.5.27",
"mongodb": "^3.6.2",
"mongoose": "^5.8.9",
"mongoose-field-encryption": "^3.0.4",
"morgan": "^1.7.0",
"ms": "^2.1.2",
"multer": "^1.4.2",
"node-schedule": "^1.3.2",
"nodemailer": "^4.7.0",
"nylas": "^4.8.0",
"parse-duration": "^0.4.4",
"stripe": "^8.32.0",
"superagent": "^5.2.1",
"validator": "^10.9.0",
"winston": "^3.1.0"
 },
 "engines": {
"node": "12.x"
 }
}

When i run npm start I get this error, Any ideas? internal/modules/cjs/loader.js:969 throw err; ^

  Error: Cannot find module '../utils/appleAuth'
  Require stack:

I have tried re installing npm, deleting my package.json folder and node modules folder. I have tried re installing the library as well with no luck. Every time I use npm start I get the same error. I am pretty new to api's and would love some help. thank you!

0

There are 0 answers