A simple package designed to streamline the development of a zero-knowledge authentication system with Zupass tickets.
The repository includes the zuauth package along with a documented example demonstrating how to create an authentication system using NextJS and IronSession. Use the demo and refer to the tutorial section below to understand how to integrate zuauth into your app. |
---|
Install the zuauth
package with npm:
npm i zuauth
or yarn:
yarn add zuauth
Note
The example in the repository uses iron-session
to manage sessions, but you are of course free to integrate your preferred solution.
First, you need to create the server-side logic to generate a session nonce and perform the authentication. The example in this repository includes four functions: login, logout, nonce, and user. Remember to add all necessary checks in your login function, particularly ensuring that the ticket has been issued by Zupass and that it is among the supported tickets.
Next, you can proceed with the client side.
- Create a page for the Zupass popup:
zuauth/example/src/pages/popup.tsx
Lines 1 to 10 in c7c052a
- Create another page and define the default set of ticket fields to reveal.
zuauth/example/src/pages/index.tsx
Lines 11 to 23 in c7c052a
- Check if the user is logged-in.
zuauth/example/src/pages/index.tsx
Lines 26 to 45 in c7c052a
- Create a function to login, which generates a nonce and user's PCD:
zuauth/example/src/pages/index.tsx
Lines 58 to 70 in c7c052a
- Check when the PCD is generated and returned by the Zupass popup to call the login API:
zuauth/example/src/pages/index.tsx
Lines 47 to 56 in c7c052a
Important
When the user interacts with the Zupass popup, the output, which is the generated PCD, is not returned by any function but can be found in the pcd
state variable within the useZuAuth
hook. It's important to check if the value is defined.
- Create a function to allow users to log out:
zuauth/example/src/pages/index.tsx
Lines 72 to 82 in c7c052a
- Create your UI:
zuauth/example/src/pages/index.tsx
Lines 161 to 194 in c7c052a