Get Current User
The getUser
method retrieves information about the currently authenticated user.
Definition
zkdb.auth.getUser(): TUserMeResponse | undefined;
Parameters
- None
Returns
TUserMeResponse | undefined
: Returns the current user's profile information (username, email, public key, and user data) if authenticated, orundefined
if not logged in. This provides immediate access to cached user information without making an API call.
type TUserMeResponse = {
userName: string;
email: string;
publicKey: string;
userData: Record<string, any> | null;
};
Example
import { ZkDatabase } from 'zkdb';
const zkdb = await ZkDatabase.connect({
userName: "chiro-user",
privateKey: "EKFTciRxyxshZjimay9sktsn7v5PvmC5zPq7q4JnitHUytxUVnFP",
environment: "node",
// This URL is for test environment
url: "https://api.zkdatabase.org/graphql",
});
await zkdb.auth.signIn();
console.log('Current user:', zkdb.auth.getUser());
await zkdb.auth.signOut();
Result:
Current user: {
"userName": "chiro-user",
"email": "[email protected]",
"publicKey": "B62qqAHb9dveVJY58GUGjL6CfCBDJL5DmUcUpkAA71pLTYCYxHzJVVG",
"userData": {}
}