React
Follow this quickstart tutorial to add authentication to your React application
Last updated
Was this helpful?
Follow this quickstart tutorial to add authentication to your React application
Last updated
Was this helpful?
Signup for an account in https://portal.authgearapps.com/ and create a Project.
After that, we will need to create an Application in the Project Portal.
Go to Applications in your project portal.
Click Add Application in the top right corner.
Input the name of your application. This is for reference only.
Decide a path in your website that users will be redirected to after they have authenticated with Authgear. Add the URI to Redirect URIs. e.g.http://localhost:3000/auth-redirect
for this tutorial.
Select the Issue JWT as access token option. We will use Token-based authentication for this tutorial.
Click "Save" and keep the Client ID. You can also obtain it from the Applications list later.
Go to Applications > Allowed Origins.
Add your website origin to the allowed origins. Set tolocalhost:3000
for this tutorial.
Click "Save".
If you don't already have an existing React application, you can create one using Create React App. Skip this part if you are integrating Authgear to your existing application.
Run the following command within your React project directory to install the Authgear Web SDK
To access restricted resources on your application server, the HTTP requests should include the access token in their Authorization headers. The Web SDK provides a fetch
function which automatically handle this, or you can get the token with authgear.accessToken
.
Authgear SDK provides the fetch
function for you to call your application server. This fetch
function will include the Authorization header in your application request, and handle refresh access token automatically. The authgear.fetch
implements fetch.
You can get the access token through authgear.accessToken
. Call refreshAccessTokenIfNeeded
every time before using the access token, the function will check and make the network call only if the access token has expired. Include the access token into the Authorization header of the application request.
This page is working in progress, please see Get Started: Web SDK for general guides of using the Authgear Web SDK