remix-utils
Version:
This package contains simple utility functions to use with [React Router](https://reactrouter.com/).
44 lines (43 loc) • 1.81 kB
TypeScript
import { type unstable_MiddlewareFunction, type unstable_RouterContextProvider } from "react-router";
export declare function unstable_createBasicAuthMiddleware(options: unstable_createBasicAuthMiddleware.Options): unstable_createBasicAuthMiddleware.ReturnType;
export declare namespace unstable_createBasicAuthMiddleware {
export type Args = {
request: Request;
context: unstable_RouterContextProvider;
};
export type MessageFunction = (args: Args) => string | object | Promise<string | object>;
interface BaseOptions {
/**
* The domain name of the realm, as part of the returned WWW-Authenticate
* challenge header.
* @default "Secure Area"
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/WWW-Authenticate#directives
*/
realm?: string;
hashFunction?: HashFunction;
invalidUserMessage?: string | object | MessageFunction;
}
export interface User {
/**
* The username of the user who is authenticating.
*/
username: string;
/**
* The password value for the provided username to authenticate against.
*/
password: string;
}
export interface HardCodedUserOptions extends BaseOptions {
user: User | Array<User>;
}
export interface DynamicUserOptions extends BaseOptions {
verifyUser(username: string, password: string, args: Args): boolean | Promise<boolean>;
}
export type Options = HardCodedUserOptions | DynamicUserOptions;
export type ReturnType = [
middleware: unstable_MiddlewareFunction<Response>,
(context: unstable_RouterContextProvider) => User["username"]
];
export type HashFunction = (data: Uint8Array) => Uint8Array;
export {};
}