verifyBasicAuth

View as MarkdownOpen in Claude

Verify a Basic Auth username/password pair against the configured credentials. Uses a constant-time comparison to prevent timing attacks. Useful for custom auth flows where you need to check credentials outside a middleware context.

Returns false immediately when Basic Auth is not configured (i.e., basicAuth was not passed to the constructor). For full request validation including Bearer and API key fallbacks, use validate() or attach middleware() to your Hono app.

Parameters

username
stringRequired

The username to verify.

password
stringRequired

The password to verify.

Returns

booleantrue if the credentials match; false if they don’t, or if Basic Auth was not configured.

Example

1import { AuthHandler } from '@signalwire/sdk';
2
3const auth = new AuthHandler({
4 basicAuth: ['admin', 'secret-password'],
5});
6
7function login(username: string, password: string) {
8 if (auth.verifyBasicAuth(username, password)) {
9 return { ok: true, user: username };
10 }
11 return { ok: false };
12}