- Install the Basic React SDK into an existing React project
- Connect to a Basic project and customize the schema
- Add sign in and sign out functionality
This library is only for client-side React. A NextJS library is coming soon!
This is for existing React projects. If you’re starting afresh, consider creating a lofi app.
Installation
1
Install the @basictech/react library
cd project-name
into your project, run npm i
and install the @basictech/react
library in your app:Terminal
Set up basic.config
1
Create a basic.config.ts file
Create a new file called
basic.config.ts
in the root of your project. You can either do this manually, or go through the CLI flow to have it automatically created for you.2
Customize the config
Add your project ID to the
basic.config.ts
file, and customize the schema in the file. You can copy your schema from the Basic dashboard and paste it into the file.Any changes you make to the schema in basic.config need to eventually be deployed to the Basic dashboard. Local changes would be for development purposes only.basic.config.ts
Adding Auth
1
Add the BasicProvider to main.tsx
Navigate to
src/main.tsx
, add the BasicProvider to imports, and wrap your app in it.
Replace YOUR_PROJECT_ID with your Project ID from the Basic dashboard. To create one, follow the instructions for signing up.
main.tsx
2
Add a login button to App.tsx
Now navigate to Let’s test it out! Clicking on the button should now redirect you to the Basic.id page where your users can login or create an account.
Once they’re done, they’ll be redirected back to your app and see their email displayed.
src/App.tsx
and import signin
, isSignedIn
, and user
. Vite comes with some template code, but you can replace the contents with the following:App.tsx
3
Add a logout button
Use the isSignedIn hook to check if the user is logged in, and the signout function to sign out the user:That’s it! You’ve successfully added Basic Auth to your React app 🎉
App.tsx