Skip to content

Instantly share code, notes, and snippets.

@johanbaaij
Last active January 8, 2020 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johanbaaij/08b1222d3c8283278985138f3ca6834c to your computer and use it in GitHub Desktop.
Save johanbaaij/08b1222d3c8283278985138f3ca6834c to your computer and use it in GitHub Desktop.
import { Vue } from "vue/types/vue";
interface AuthOptions {
params?: {};
success?: () => void;
error?: () => void;
}
type Redirect = { path: string } | string;
interface LoginOptions extends AuthOptions {
rememberMe?: boolean;
redirect?: Redirect;
fetchUser?: boolean;
}
interface FetchOptions extends AuthOptions {}
interface LogoutOptions extends AuthOptions {
makeRequest?: boolean;
redirect?: Redirect;
}
interface Oauth2Options extends AuthOptions {
code?: boolean;
provider: string;
redirect?: Redirect;
rememberMe?: boolean;
}
interface RefreshOptions extends AuthOptions {}
interface RegisterOptions extends AuthOptions {
autoLogin?: true;
rememberMe?: boolean;
redirect?: Redirect;
}
interface ImpersonateOptions extends AuthOptions {
redirect?: Redirect;
}
interface UnimpersonateOptions extends AuthOptions {
redirect?: Redirect;
makeRequest?: boolean;
}
interface UserInterface {
[key: string]: any;
email?: string;
name?: string;
roles?: string[];
}
interface VueAuth {
/**
* Get binded ready property to know when user is fully loaded and checked.
* Can also set a single callback which will fire once (on refresh or entry)
*
* @param {() => void} callBack
* @returns {boolean}
*/
ready(callBack?: () => void): boolean;
/**
* Data object is passed directly to http method.
*
* @param {LoginOptions} options
*/
login(options: LoginOptions): void;
/**
* Fetch the user (again) allowing the users data to be reset (from the api).
* Data object is passed directly to http method
*
* @param {FetchOptions} options
*/
fetch(options: FetchOptions): void;
logout(options: LogoutOptions): void;
oauth2(options: Oauth2Options): void;
refresh(options: RefreshOptions): void;
register(options: RegisterOptions): void;
impersonate(options: ImpersonateOptions): void;
unimpersonate(options: UnimpersonateOptions): void;
disableImpersonate(): void;
enableImpersonate(): void;
token(tokenName?: string, token?: string): string;
redirect(): void;
check(role?: string, key?: string): boolean;
user(data?: any): UserInterface;
}
declare module "vue/types/vue" {
interface Vue {
$auth: VueAuth;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment