Created
October 7, 2019 08:25
-
-
Save danielroe/2d5ee5de4439edc358a1a8aeb54feac4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { CookieAttributes } from 'js-cookie' | |
interface StorageCookieOptions extends CookieAttributes { | |
cookie: { | |
prefix: string | |
options?: StorageCookieOptions | |
} | |
} | |
interface Storage { | |
setUniversal(key: string, value: any, isJson?: boolean): string | |
getUniversal(key: string, isJson?: boolean): any | |
syncUniversal(key: string, defaultValue: any, isJson?: boolean): any | |
// Local State | |
setState(key: string, val: any): string | |
getState(key: string): string | |
watchState(key: string, handler: (newValue: any) => void): any | |
// Cookies | |
setCookie(key: string, val: any, options?: StorageCookieOptions): any | |
getCookie(key: string, isJson?: boolean): any | |
// Local Storage | |
setLocalStorage(key: string, val: any, isJson?: boolean): any | |
getLocalStorage(key: string, isJson?: boolean): any | |
} | |
export interface Auth<T = any> { | |
ctx: any | |
$state: any // todo: type this | |
$storage: Storage | |
user: Partial<T> | |
loggedIn: boolean | |
loginWith(strategyName: string, ...args: any[]): Promise<void> | |
login(...args: any[]): Promise<void> | |
logout(): Promise<void> | |
fetchUser(): Promise<void> | |
fetchUserOnce(): Promise<void> | |
hasScope(scopeName: string): boolean | |
setToken(strategyName: string, token?: string): string | |
syncToken(strategyName: string): string | |
onError(handler: (error: Error, name: string, endpoint: any) => void): any | |
setUser(user?: Partial<T>): any | |
reset(): Promise<void> | |
redirect(name: string): any | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment