nostrbasedocs
Start building
Guide
.md

Choose a signer

import { PrivateKeySigner, NostrConnectSigner } from "nostrbase";

// Use a secret supplied by the user or generate a temporary development identity.
await db.auth.signInWithPrivateKey(privateKey); // Uint8Array, hex, or nsec.
await db.auth.signInWithSigner(new PrivateKeySigner());

// Use an Applesauce NIP-46 remote signer.
const signer = await NostrConnectSigner.fromBunkerURI(bunkerUri, { pool: db.pool });
await db.auth.signInWithSigner(signer);

const { data: session } = await db.auth.getSession();
const { data: user } = await db.auth.getUser();
const { data: { subscription } } = db.auth.onAuthStateChange((event, session) => {
  console.log(event, session?.user.pubkey);
});
subscription.unsubscribe();
await db.auth.signOut();

A session holds a public key. Signing is handled by Applesauce. There is no JWT or server session. The SDK does not persist keys or sessions. Sign-out clears the SDK session; the app owns the signer and must close a remote signer when needed. A generated private key is temporary unless your app saves it.

Auth proves control of a key. Your app must decide which authors it trusts. If a relay requires NIP-42 auth, use db.pool.relay(url).authenticate(signer) before the operation; relay authentication is not automatic.

Search guides, API methods, and protocols.