- Live demo for PKCE flow with refresh token rotation.-
- For non-logged in users, there is a
Loginbutton for authorization redirect - For 'logged in' users (supposedly with refresh token), there will be
Logoutbutton to clear token and go back to login. - There is a toggle to count down and refresh token just before expiry (or immediately, if already expired). Without auto-refresh, token refresh takes place on page load.
- Codes and tokens are stored in cookies and LocalStorage by default.
- Experimental automagic token refresh with a toggle.
- Experimental due to React's Effects, there might be multiple invocations of the same requests and may cause the component to re-render few times so there's AbortController to try and cancel other requests.
libhas the PKCE module.srchas the example website to show how PKCE works, by importinglibmodule and executes PKCE token exchange and refresh flows.App.tsxis the main page that followed the PKCE RTR flowcomponentshas non-business logic components (so far only 1)stylesfor CSS (and maybe design tokens) but most stylings are done via atomic classesservicesfor neither styles nor components, like hooks or utilites, or test helpers.
- Testing is done with:
vitestas runner.testing-libraryandjsdomfor React rendering, besides default Node env for plain JS such aslibmodule.- Ideally integration over unit testing to reduce mocking surfaces and less time than E2E/headless browser setup such as BrowserStack.
Minimal setup to leave implementation room for actual business logic:
fetchfor consistent fetch API between browser and Node environment (for tests).dayjsfor time format.js-cookiefor consistent cookies handling between browser and Node environment (for tests).
- npm i -g pnpm
- pnpm i
OR npm i would also work, by ignoring the commited pnpm lockfile.
- Development mode with
pnpm dev - Test with
pnpm test - Check test coverage with
pnpm coverage
- Library/module build with
pnpm buildwhose output can be found indistfolder. - Example website build with
pnpm build:sitewhose output can be found insitefolder. - Vite's library mode is enough for the demo's scope, as monorepos would be the proper (and overkill) solution.