Skip to main content

Sign-In

The signIn method is used to authenticate an existing user in zkDatabase. The user must sign in using their email, and the signing process is validated using the previously provided signer.

Definition

await zkdb.auth.signIn(): Promise<TUserSignInResponse>;

Parameters

  • None

Returns

  • Promise<TUserSignInResponse>: Returns user profile information and access token upon successful authentication. The token is automatically stored in the client's storage and used for subsequent API calls, while the user data provides immediate access to account information.
type TUserSignInResponse = {
userName: string;
email: string;
publicKey: string;
activated: boolean;
userData: Record<string, any> | null;
accessToken: string;
};

Example

In this example, the signIn method authenticates the user with the username chiro-user.

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",
});

console.log(await zkdb.auth.signIn());

Result:

{
"userName": "chiro-user",
"accessToken": "eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6ImNoaXJvLXVzZXIiLCJlbWFpbCI6ImNoaXJvQGV4YW1wbGUuY29tIiwiZXhwIjoyMjU2ODQ1OTY2MDF9.-Y4kSFSazvgMfIUIgl1wwgMAe33-UAWm45D4RaERvkk",
"userData": {},
"publicKey": "B62qqAHb9dveVJY58GUGjL6CfCBDJL5DmUcUpkAA71pLTYCYxHzJVVG",
"email": "[email protected]"
}