hmmStart
An example CRUD PWA app with user authentication.
View the app at https://hmmstart.vercel.app/
Built with
- Next.js
- Styled Components
- Ant Design
- Formik
- Apollo Client
- Apollo Server
- Prisma
Features
- User sign up/in/out
- Progressive Web App
- Password resets
- Create/Read/Update/Delete ideas
- Individual routes for ideas
- Cursor based pagination
- Form validation
- Local GraphQL schema
- Access token refreshing
- Refresh token versioning
- Mailtrap.io integration
- Normalize CSS
- Global CSS style and theming
- Webpack Bundle Analyzer
- Accessibility auditing
- Code linting
Lighthouse audit
Testing
- React Testing Library
Refreshing Authentication
- On sign-in or sign-up, a long-lived Refresh JWT and short-lived Access JWT are generated by the Apollo server.
- The Refresh token is stored in a cookie.
- The Access token is included in the graphQL response.
- On the client, the Access token is stored in a global variable for subsequent requests.
- Using Apollo Client middleware, the Access token is validated before every request.
- If the Access token is expired, the middleware fetches a new one from the express server.
- which validates the Refresh token before sending a new Access token.
- The Refresh token can be invalidated by incrementing the version.
- This is done by making a graphQL request of:
- mutation { revokeRefreshToken(id: "some-user-id") }
- This will prevent the Access token from refreshing until the user signs in again.
- This is done by making a graphQL request of:
Getting Started
Clone project
git clone https://github.com/hmmChase/hmmStart.git
Install dependencies
- Navigate to project root
cd hmmStart
- Run
npm install
- Run
npm run frontend:install
- Run
npm run backend:install
Set environment variables
- Locate
.env.example
in both/frontend
and/backend
- Make a copy of both
- Rename copy to just
.env
Setup Prisma server
For simplicity's sake, we are using a demo server.
- Navigate to
/backend
- Run
npm run deploy -- -n
- Select
Demo server
- Complete the prompts
- Copy
HTTP
endpoint - Paste endpoint in
.env
asPRISMA_ENDPOINT
value - Run
npm run schema
- Do this everytime you make a change to
datamodel.prisma
- Do this everytime you make a change to
Setup Mailtrap
Can skip if you don't try to reset a password.
- First time
- Visit Mailtrap and sign up
- Create demo inbox
- Copy
Host
,Port
,Username
, andPassword
values - Paste in
/backend/.env
Start the app
- Navigate to root
/
- Run
npm run app
- Visit
http://localhost:8008/
Deploy to Vercel
No guarantee this will work.
- First time
- Visit Vercel and sign up
- Install Vercel Desktop and login
- Navigate to root
/
- Run
vercel
- Copy aliased URL
- Follow
vercel-secrets.md
to setup secrets - Run
vercel
- Visit the URL