Skip to content

Latest commit

 

History

History
96 lines (59 loc) · 4.54 KB

opt-in.md

File metadata and controls

96 lines (59 loc) · 4.54 KB

Use Case 2: User Opt-in

[Watch the video

Introduction

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.

Prerequisites

Before implementing the Early Access use case, ensure you have:

Implementation Steps

Follow the steps below to implement the User Opt-in use case in our demo React app:

1. Configure Your Auth0 Application

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

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/callback to the list of Allowed Callback URLs.

2. Configure Your DevCycle Project

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 Permission feature called user-optin and set the initial variable key to optin with the type boolean.

Create New Definition

  • In the Users & Targeting rules for your Development environment, select the All Users dropdown in the Definition section and scrolldown to Add Property:
    • set Property Key to optin and Property Type to boolean

Create Targeting Rules

  • In the Users & Targeting rules 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

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_****}'

3. Test Out User Opt-in

  • 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-in from 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 on position and the confetti should disappear when in the off position.

Notes

  • 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.