I am creating a config.js file having say an object known as contextTokenObject
//This holds context information or the information which will be transferred at various places of the app
let contextToken = {}
module.exports = {
contextToken
}
Now, I want to add property and methods to that context object from another file (when I am creating my passport stratergy)
Instead of pasting entire code, consider passport.js file In this passport.js file,
I am importing context Token object in this file.
const contextObject = require("./config.js")
Now, say, I want to add following property to my above object
let TokenToStore = { "googleRefreshToken": refreshToken, "`googleAccessToken": accessToken, "expires_in": params.expires_in}`
Question: How can I do it?
Update: what I have tried. Like mentioned above, I have created an object and I am importing it in my passport strategy
const contextObject = require("./../config/context.js")
then in the passport callback I am doing something like this
passport.use(new GoogleStrategy({
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
callbackURL: process.env.GOOGLE_CALLBACK_URL,
userProfileURL: 'https://www.googleapis.com/oauth2/v3/userinfo',
accessType: 'offline'
}, (accessToken, refreshToken, params, profile, cb) => {
//Sorting the data we recieve and removing unwanted stuff
let profileSort = authHelper.extractGmailProfile(profile)
//Update refresh token whenever recieved
let TokenToStore = { "googleRefreshToken": refreshToken, "googleAccessToken": accessToken, "expires_in": params.expires_in}
//Context object
contextObject.contextToken["googleToken"] = TokenToStore
This is throwing following error
Cannot set property 'googleToken' of undefined
Any help would be appreciated.