mirror of
https://github.com/directus/directus.git
synced 2026-02-05 02:14:57 -05:00
* refactor: more intuitive interfaces * refactor: simpler refresh before: on every request we were debouncing a refresh request after: call refresh only once before now() + 'expires' * refactor: prefix on base storage * fixup! refactor: simpler refresh before: on every request we were debouncing a refresh request after: call refresh only once before now() + 'expires' * refactor: simpler axios transport before: handle auth headers after: auth headers are handled on directus instance * refactor: simpler usage of Directus constructor * fixup! refactor: simpler refresh before: on every request we were debouncing a refresh request after: call refresh only once before now() + 'expires' * refactor: fix tests based on previous changes * refactor: better auth constructor before: depends on SDK instance after: depends on Transport and Storage instance * accept staticToken from auth * make transport and storage as optional on options * fix type auth refresh * simplify transport * fix test for previous changes * improve auth class * revert some IAuth props because tests * allow to force memory of localstorage on storage * add tests for previous change * document everything and simplify some things * fix override headers on request * better name typing * fix private axios * removed boolean from CLI auth.refresh() * fix missing url in some examples * soem grammar updates Co-authored-by: Jay Cammarano <jay.cammarano@gmail.com> Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
43 lines
1.0 KiB
TypeScript
43 lines
1.0 KiB
TypeScript
import { IStorage } from './storage';
|
|
import { ITransport } from './transport';
|
|
import { PasswordsHandler } from './handlers/passwords';
|
|
|
|
export type AuthCredentials = {
|
|
email: string;
|
|
password: string;
|
|
otp?: string;
|
|
};
|
|
|
|
export type AuthToken = string;
|
|
|
|
export type AuthTokenType = 'DynamicToken' | 'StaticToken' | null;
|
|
|
|
export type AuthResult = {
|
|
access_token: string;
|
|
expires: number;
|
|
refresh_token?: string;
|
|
};
|
|
|
|
export type AuthMode = 'json' | 'cookie';
|
|
|
|
export type AuthOptions = {
|
|
mode?: AuthMode;
|
|
autoRefresh?: boolean;
|
|
msRefreshBeforeExpires?: number;
|
|
staticToken?: string;
|
|
transport: ITransport;
|
|
storage: IStorage;
|
|
};
|
|
|
|
export abstract class IAuth {
|
|
mode = (typeof window === 'undefined' ? 'json' : 'cookie') as AuthMode;
|
|
|
|
abstract readonly token: string | null;
|
|
abstract readonly password: PasswordsHandler;
|
|
|
|
abstract login(credentials: AuthCredentials): Promise<AuthResult>;
|
|
abstract refresh(): Promise<AuthResult | false>;
|
|
abstract static(token: AuthToken): Promise<boolean>;
|
|
abstract logout(): Promise<void>;
|
|
}
|