@ubuilder/auth
Version:
UBuilder Auth
60 lines (59 loc) • 1.75 kB
TypeScript
import { Rest, RestOptions } from '@ubuilder/rest';
export { Rest };
export interface UserDetails {
[key: string]: unknown;
}
export interface UserBase {
token: string;
authorities: string[];
details: UserDetails;
}
interface UserData extends UserBase {
expireAt: number;
sessionExpireAt: number;
}
export interface User extends UserData {
isLoggedIn: boolean;
hasAuthority(autority?: string): boolean;
}
export interface LoginRequest {
username: string;
password: string;
remember?: boolean;
[key: string]: unknown;
}
export interface Auth {
initialized(): Promise<void>;
login(username: string, password: string, remember?: boolean): Promise<User>;
login(loginRequest: LoginRequest): Promise<User>;
logout(): Promise<void>;
refreshToken(): Promise<void>;
changePassword(oldPassword: string, newPassword: string): Promise<void>;
currentUser(): User;
rest(): Rest;
}
export declare function useAuth(authPrefix?: string): Auth;
export declare function useRest(authPrefix?: string): Rest;
export declare function currentUser(authPrefix?: string): User;
export declare function onUserChanged(callback: (user: User) => unknown, authPrefix?: string): void;
export interface AuthOptions {
baseURL: string;
apiURL: string;
storageKey: string;
restOptions?: RestOptions;
onUserChanged?: (user: User) => void;
}
export interface AuthPluginOptions extends Partial<AuthOptions> {
authPrefix?: string;
}
declare const plugin: {
install(app: any, options?: AuthPluginOptions): void;
};
export default plugin;
declare module '@vue/runtime-core' {
interface ComponentCustomProperties {
$auth: Auth;
$rest: Rest;
$user: User;
}
}