Skip to main content

Check Login Status

The isLoggedIn method checks if the user is currently authenticated in zkDatabase.

Definition

zkdb.auth.isLoggedIn(): boolean;

Parameters

  • None

Returns

  • boolean: Returns true if the user has a valid authentication session with an active access token, false if not authenticated or if the session has expired. This is a synchronous check of the local authentication state.

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('Is logged in:', zkdb.auth.isLoggedIn());

await zkdb.auth.signOut();

Result:

Is logged in: true