Flagsmith / flagsmith-js-client

Javascript Client for Flagsmith. Ship features with confidence using feature flags and remote config. Host yourself or use our hosted version at https://www.flagsmith.com/
https://www.flagsmith.com/
BSD 3-Clause "New" or "Revised" License
60 stars 38 forks source link

Different environments not working #208

Closed sathishcst10 closed 9 months ago

sathishcst10 commented 9 months ago

Hi I'm using FlagSmith for my project, its have three different environment like Dev, staging, prod, In flagSmith calling method i using different Identity keys, but still its calling only Development Environment from flagSmith.

flagsmith.init({
  environmentID : 'dev-env-id',
  cacheFlags : true,
  enableAnalytics : false,  
  identity : environment.user_identity
})
flagsmith.init({
  environmentID : 'stage-env-id',
  cacheFlags : true,
  enableAnalytics : false,  
  identity : environment.user_identity
})

In my angular code sent the stage-env-id but still in the "X-Environment-Key" header dev env id only passed.

please check and fix this asap

matthewelwell commented 9 months ago

@sathishcst10 can you share more code here? Are you initialising the client more than once in a given session?

sathishcst10 commented 9 months ago

Hi, No, I'm just initializing the client only once, the environmentID , came from the env file in angular.

dabeeeenster commented 9 months ago

You don't have flagsmith.init more than once in your codebase?

sathishcst10 commented 9 months ago

Yes, I create service module and initialize flagsmith.init once and I use it across the components, look at the sample code, which im using

import { Injectable } from '@angular/core';
import flagsmith from 'flagsmith';
import { environment } from 'src/environments/environment';

flagsmith.init({
  environmentID : environment.config_identity,
  cacheFlags : true,
  enableAnalytics : false,  
  identity : environment.user_identity
})
@Injectable({
  providedIn: 'root'
})
export class ConfigFlagsService {
  logs! : any;
  constructor() {  
  }

  get_app_name(){
    return flagsmith.getValue('app_name')
  }
}
dabeeeenster commented 9 months ago

You must be passing in the incorrect environment key.