Dynamic in PWA
In this guide we are going to setup a PWA using Dynamic and Vite, React & Typescript.
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 SDK
Install Dynamic Packages
Add the DynamicContextProvider
In the src/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 the src/App.tsx
file, we can add the DynamicWidget component
Great, now Dynamic is fully added and we can get start with the PWA setup!
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 our vite.config.ts
file with vite-plugin-pwa:
We also need to add some images like 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 to src/useInstallPWA.ts
that allows us to trigger the PWA installation:
Then we can use useInstallPWA in the src/main.tsx
file to prompt the user to install the PWA:
Perfect, now you can serve your DApp under https
and install the PWA on your computer or phone, then authenticate with Dynamic!
Was this page helpful?