UNPKG

@e280/authlocal

Version:

User-sovereign login system for everybody

40 lines (39 loc) 1.58 kB
import { AuthOptions } from "./types.js"; import { defaults } from "./parts/defaults.js"; import { Login } from "../trust/exports/app.js"; /** * Authlocal's page-level auth control center. * - there should only be one instance on the page, shared across any authlocal elements. * - provides the `login` state * - handles persistence of the login session into storage * - coordinates and communicates with the Authlocal popup */ export declare class Auth { #private; static version: number; static defaults: typeof defaults; /** The url that the login popups should use (defaults to "https://authlocal.org/") */ src: string; /** * Subscribe to changes in the login state. * - if the login is `null`, it means the user has logged out. * - usage: * auth.on(login => console.log(login)) */ on: import("@e280/stz").Sub<[Login | null]>; constructor(options?: Partial<AuthOptions>); /** Load and update the login state from storage */ loadLogin(): Promise<Login | null>; /** Set the login state manually, saving it to storage */ saveLogin(login: Login | null): Promise<Login | null>; /** Shortcut for `saveLogin(null)` */ logout(): Promise<Login | null>; /** The current login state, either a `Login` object, or null if logged out */ get login(): Login | null; /** * Spawn a login popup, requesting for the user to login. * `src`: * this is the url to open (defaults to "https://authlocal.org/") */ popup(src?: string): Promise<Login | null>; }