UNPKG

@nextcloud/auth

Version:

Nextcloud helpers related to authentication and the current user

36 lines (35 loc) 1.11 kB
/** * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: GPL-3.0-or-later */ export interface CsrfTokenObserver { (token: string): void; } /** * Get current request token * * @return Current request token or null if not set */ export declare function getRequestToken(): string | null; /** * Set a new CSRF token (e.g. because of session refresh). * This also emits an event bus event for the updated token. * * @param token - The new token * @throws {Error} - If the passed token is not a potential valid token */ export declare function setRequestToken(token: string): void; /** * Fetch the request token from the API. * This does also set it on the current context, see `setRequestToken`. * * @throws {Error} - If the request failed */ export declare function fetchRequestToken(): Promise<string>; /** * Add an observer which is called when the CSRF token changes * * @param observer The observer * @return A function to unsubscribe the observer */ export declare function onRequestTokenUpdate(observer: CsrfTokenObserver): () => void;