The ZkEmailSDKProvider is a wrapper component that provides the ZK Email SDK context to its children. It manages the core functionalities of the SDK, including input generation, proof creation, and interaction with the ZK Email SDK registry.
Props
Prop
Type
Description
children
ReactNode
Child components to be wrapped
clientId
string
Google OAuth client ID
zkEmailSDKRegistryUrl
string
URL for the ZK Email SDK registry
Ensure that your clientId is kept secret and not exposed in client-side code.
Usage
import{ZkEmailSDKProvider}from"@zk-email/zk-email-sdk";functionApp(){return (<ZkEmailSDKProviderclientId={import.meta.env.VITE_GOOGLE_OAUTH_CLIENT_ID}zkEmailSDKRegistryUrl='https://registry-dev.zkregex.com'>{/* Your app components */}</ZkEmailSDKProvider> );}exportdefaultApp;
The GoogleAuthProvider is a wrapper component that manages Google authentication state and provides authentication-related functions to its child components. It's an essential part of the ZK Email SDK that simplifies the process of integrating Google authentication into your application.
Props
Prop
Type
Description
children
ReactNode
Child components that will have access to the authentication context
Hooks
useZkEmailSDK
The useZkEmailSDK hook provides access to ZK Email SDK functionalities, allowing components to interact with the core features of the SDK.
Ensure that you're calling this hook within a component that is a child of ZkEmailSDKProvider, otherwise it will throw an error.
useGoogleAuth
The useGoogleAuth hook provides access to Google authentication functionalities, allowing components to check authentication status and perform login/logout operations.
Returns
Property
Type
Description
googleAuthToken
any | null
Google authentication token
isGoogleAuthed
boolean
Whether the user is authenticated with Google
loggedInGmail
string | null
Email of the logged-in user
scopesApproved
boolean
Whether all required scopes are approved
googleLogIn
() => void
Initiates Google login
googleLogOut
() => void
Logs out from Google
The googleAuthToken is automatically stored in local storage for persistence across page reloads.
Utility Functions
fetchEmailList, fetchEmailsRaw, fetchProfile
These functions fetch email data and user profile information using the provided Google authentication token.
These functions should only be called after successful Google authentication and with a valid token.