Full code example
You can find the full code from this example here.Pre-requisites
- Node installed
- Boilerplate project created with Vite
Dynamic Setup
With a basic project in place, we can now setup the Dynamic React SDKInstall Dynamic Packages
Add the DynamicContextProvider
In thesrc/main.tsx file we can add the DynamicContextProvider with an environment ID
Add the DynamicWidget
Over in the App file, we are going to use the DynamicWidget for users to be able to authenticate using the Dynamic UI Now, in thesrc/App.tsx file, we can add the DynamicWidget component
PWA Setup
Install Dependencies
Setup PWA
For this app to became a PWA we will need to generate a manifest file with some extra icons that the OS will use. First, we can update ourvite.config.ts file with vite-plugin-pwa:
logo.png and apple-touch-icon.png to our public to serve as the PWA icons.
Now we have to specify in the index.html file some basic information about the PWA:
So, add the following to the head tag
Add an Install Button
Let’s add an install button so users can install our PWA. We can add a hook tosrc/useInstallPWA.ts that allows us to trigger the PWA installation:
src/main.tsx file to prompt the user to install the PWA:
https and install the PWA on your computer or phone, then authenticate with Dynamic!