React

Setup

Before we get started building our web application, we need to complete a few set up steps.


Step 1: Sign Up For a Smartcar Account

Go to our Developer Dashboard to sign up with Smartcar.

Step 2: Retrieve Your API Credentials

Once you have made your account, you will notice you already have an application with API keys. You will need these keys to complete this tutorial.

Step 3: Configure Your Redirect URI

You will need to set a redirect_uri for your application. We will be using this in the next section. For now, you can just set it to https://javascript-sdk.smartcar.com/redirect-2.0.0?app_origin=http://localhost:3000. For more information about redirect URI's, refer to our docs.

Step 4: Clone the Starter Kit

First, set the following environment variables -

  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
export REACT_APP_CLIENT_ID=<your-client-id>
export REACT_APP_REDIRECT_URI=https://javascript-sdk.smartcar.com/redirect-2.0.0?app_origin=http://localhost:3000
Note: If you are using Windows, ensure you are appropriately setting environment variables for your shell. Please refer to this post which details how to set environment variables on Windows.

We will be setting up a server later for our React front-end to communicate with. For now, let's assume our server is listening on http://localhost:8000 and store it in an environment variable -

  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
export REACT_APP_SERVER=http://localhost:8000

Make sure you have cloned this repo and install the required dependencies -

  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
git clone https://github.com/smartcar/getting-started-javascript-sdk-react.git
cd getting-started-javascript-sdk-react/tutorial
npm install
Note: If you want to run the React app without writing any code, follow along with the Readme.

Now that we've set up our application, let's learn more about Smartcar's authorization flow.