Feature flags aren't solely for developers and product managers. With DevCycle, users can also toggle new features on or off themselves. This is a great way to get early feedback from users and to test new features before rolling them out to everyone. In this use case demo, we show you how to create a feature flag that users can toggle on or off themselves.
Before implementing the Early Access use case, ensure you have:
- Followed the installation instructions from the main README.md
- Created an account on devcycle.com
- Created an account on Auth0.com
Follow the steps below to implement the User Opt-in use case in our demo React app:
Get Your Application Keys
- When you signed up for Auth0, a new application was created for you, or you could have created a new one. You will need some details about that application to communicate with Auth0. You can get these details from the Application Settings section in the Auth0 dashboard.
Add keys to .env.local file
- In the root directory of your project copy the .env.local.example file to .env.local and add the following environment variables:
AUTH0_SECRET='use [openssl rand -hex 32] to generate a 32 bytes value'
AUTH0_BASE_URL='http://localhost:3000'
AUTH0_ISSUER_BASE_URL='https://{yourDomain}'
AUTH0_CLIENT_ID='{yourClientId}'
AUTH0_CLIENT_SECRET='{yourClientSecret}'
Create Sample Users
- Create three different users in your Auth0 tenant by visiting the User Management section in the Auth0 dashboard.
Add Localhost to Callback URLs
- Before You leave the Auth0 Dashboard, find the Application URIs section under Application Settings and add
http://localhost:3000/api/auth/callbackto the list of Allowed Callback URLs.
Create a New Project
- In the DevCycle Dashboard, create a new project. Name the project some variation of Use Cases
Create a New Feature
- In this new project, create a new
Permissionfeature called user-optin and set the initial variable key to optin with the type boolean.
Create New Definition
- In the
Users & Targetingrules for your Development environment, select theAll Usersdropdown in the Definition section and scrolldown toAdd Property:- set Property Key to optin and Property Type to boolean
Create Targeting Rules
- In the
Users & Targetingrules for your Development environment, create a targeting rule with the following values:- Name:
User Optin On - Definition:
optin is true - Serve:
Configuration 1 - Schedule:
None
- Name:
Add SDK key to .env file
- Select the key icon (View API Keys) in the main navbar, and copy the client key for your Development Environment (it should look like dvcclient****)
- In the root directory of your project copy the .env.example file to .env and update it with the following environment variable:
NEXT_PUBLIC_DVC_SDK_KEY='{dvc_client_****}'
- Ensure your demo application is running at https://localhost:3000 by following the instructions in the main README.md file.
- Login as developer@domain1.com using the credentials you created in Step 1, and select the
User Opt-infrom the sidebar menu. - Click the User Opt-in Toggle.
- If the DevCycle SDK has been successfully configured you should see confetti when the toggle is in the
onposition and the confetti should disappear when in theoffposition.
- If the DevCycle SDK has been successfully configured you should see confetti when the toggle is in the
- The User Opt-in feature flag can also be managed via the DevCycle CLI.
- Please refer back to the main README.md file for general instructions and contact information if any problems are encountered.