Files
directus/packages/sdk/src/auth.ts
João af13cfe18e Change token and auth handling behavior. (#5203)
* change tokens and authentication handling/refresh

* update sdk docs
2021-04-22 17:54:30 -04:00

36 lines
762 B
TypeScript

import { PasswordsHandler } from './handlers/passwords';
export type AuthCredentials = {
email: string;
password: string;
otp?: string;
};
export type AuthToken = string;
export type AuthResult = {
access_token: string;
expires: number;
refresh_token?: string | null;
};
export type AuthLoginOptions = {
refresh?: AuthRefreshOptions;
};
export type AuthRefreshOptions = {
auto?: boolean;
time?: number;
};
export interface IAuth {
readonly token: string | null;
readonly password: PasswordsHandler;
readonly expiring: boolean;
login(credentials: AuthCredentials, options?: AuthLoginOptions): Promise<AuthResult>;
refresh(force?: boolean): Promise<AuthResult | false>;
static(token: AuthToken): Promise<boolean>;
logout(): Promise<void>;
}