mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
@nuxtjs/auth typings (#38132)
* Add nuxt auth module typings first draft * Remove js-cookie dependency * Fix lint for nuxt/auth * Fix types reference
This commit is contained in:
parent
2455292097
commit
0ebd4b8fc9
57
types/nuxtjs__auth/index.d.ts
vendored
Normal file
57
types/nuxtjs__auth/index.d.ts
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
// Type definitions for @nuxtjs/auth 4.8
|
||||
// Project: https://auth.nuxtjs.org
|
||||
// Definitions by: Ruskin Constant <https://github.com/jonnyparris>
|
||||
// Daniel Leal <https://github.com/danielgek>
|
||||
// Nick Bolles <https://github.com/NickBolles>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 3.1
|
||||
|
||||
import Vue, { ComponentOptions } from 'vue';
|
||||
|
||||
export 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?: object): 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;
|
||||
$storage: Storage;
|
||||
user: Partial<T>;
|
||||
loggedIn: boolean;
|
||||
loginWith(strategyName: string, ...args: any): Promise<never>;
|
||||
login(...args: any): Promise<never>;
|
||||
logout(): Promise<never>;
|
||||
fetchUser(): Promise<never>;
|
||||
fetchUserOnce(): Promise<never>;
|
||||
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<never>;
|
||||
redirect(name: string): any;
|
||||
}
|
||||
|
||||
declare module 'vue/types/options' {
|
||||
interface ComponentOptions<V extends Vue> {
|
||||
auth?: boolean | string;
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'vue/types/vue' {
|
||||
interface Vue {
|
||||
$auth: Auth;
|
||||
}
|
||||
}
|
||||
16
types/nuxtjs__auth/nuxtjs__auth-tests.ts
Normal file
16
types/nuxtjs__auth/nuxtjs__auth-tests.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import Vue from 'vue';
|
||||
|
||||
new Vue({
|
||||
el: '#app',
|
||||
methods: {
|
||||
logout(): void {
|
||||
this.$auth.logout();
|
||||
},
|
||||
},
|
||||
template: `
|
||||
Logout
|
||||
<a @click="logout">
|
||||
Logout
|
||||
</a>
|
||||
`,
|
||||
});
|
||||
6
types/nuxtjs__auth/package.json
Normal file
6
types/nuxtjs__auth/package.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"vue": "^2.6.10"
|
||||
}
|
||||
}
|
||||
19
types/nuxtjs__auth/tsconfig.json
Normal file
19
types/nuxtjs__auth/tsconfig.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6", "dom"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"paths": {
|
||||
"@nuxtjs/auth": ["nuxtjs__auth"]
|
||||
}
|
||||
},
|
||||
"files": ["index.d.ts", "nuxtjs__auth-tests.ts"]
|
||||
}
|
||||
1
types/nuxtjs__auth/tslint.json
Normal file
1
types/nuxtjs__auth/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user