# Authentication

Signer sessions and auth state listeners.

[Read the connect a signer guide](/docs/authentication/). Signatures below come from the published SDK declarations. Access SDK services through `db`; use their constructors only when integrating at a lower level.

## NostrbaseAuth


```ts
declare class NostrbaseAuth {}
```

### Properties


```ts
get revision(): number;
/** Replaced on every auth revision. The previous signal aborts before pending sign-in work. */
get revisionSignal(): AbortSignal;
/** @internal True when the current auth transition has completed, including failed sign-in. */
get revisionSettled(): boolean;
```

### onRevisionSettled


```ts
/** @internal Observe completed auth transitions without emitting a public successful sign-in. */
onRevisionSettled(callback: () => void): {
  unsubscribe(): void;
};
```

### constructor


```ts
constructor(signer?: Signer);
```

### signInWithSigner


```ts
signInWithSigner(signer: Signer): Promise<Result<Session>>;
```

### signInWithExtension


```ts
signInWithExtension(): Promise<Result<Session>>;
```

### signInWithPrivateKey


```ts
signInWithPrivateKey(key: Uint8Array | string): Promise<Result<Session>>;
```

### exportKey


```ts
/** Export only a password-encrypted NIP-49 key from the active local PrivateKeySigner. */
exportKey(password: string, options?: KeyEncryptionOptions): Promise<Result<string>>;
```

### signInWithEncryptedKey


```ts
/** Recover a local signer from a password-encrypted NIP-49 key without exposing raw bytes. */
signInWithEncryptedKey(
  ncryptsec: string,
  password: string,
  options?: KeyDecryptionOptions,
): Promise<Result<Session>>;
```

### getSession


```ts
getSession(): Promise<Result<Session>>;
```

### getUser


```ts
getUser(): Promise<Result<User>>;
```

### signOut


```ts
signOut(): Promise<Result<null>>;
```

### onAuthStateChange


```ts
onAuthStateChange(callback: (event: AuthChange, session: Session | null) => void): {
  data: {
    subscription: {
      unsubscribe(): void;
    };
  };
};
```

### requireSigner


```ts
requireSigner(): Promise<{
  signer: Signer;
  session: Session;
}>;
```

### dispose


```ts
dispose(): void;
```
