Date of slack thread: 6/19/24
Anonymous: Hi! <@U05BQSUQM7X> and I encountered an issue with localMode
in initialize
when doing some testing. It seems that it tries to validate a secret key by making a network call, which it shouldn’t be doing. We tried using secret-key
as documented in https://docs.statsig.com/server/nodejsServerSDK#statsig-options but it did not seem to work. Error message is:
Error: Invalid key provided. You must use a Server Secret Key from the Statsig console with the node-js-server-sdk
EDIT changed to secret-key, was looking at the wrong docs
Anonymous: We do something like:
const initStatsig = async() => {
try {
const edgeConfigClient = createClient(EDGE_CONFIG_STATSIG)
const dataAdapter = new EdgeConfigDataAdapter({
// settings here
})
await Statsig.initialize(STATSIG_SERVER_API_KEY), {
// settings here
})
} catch {
await Statsig.initialize("secret-key", {
localMode: true,
environment: { /* settings here */ },
})
}
}
Anonymous: Testing locally, when I only do one initialization with localMode
, it does not seem to generate errors:
const initStatsig = async() => {
try {
await Statsig.initialize("secret-key", {
localMode: true,
environment: { /* settings here */ },
})
} catch (error) {
console.error(error)
}
}
So maybe the issue is related to doing initialize
twice?
Anonymous: Initializing twice shouldn’t matter, using secret-key should bypass that error. Are you saying the edge config + “secret-key” still had this issue?