-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathtemplates.ts
86 lines (79 loc) · 2.29 KB
/
templates.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { addTypeTemplate, type Resolver } from '@nuxt/kit'
import { relative, resolve } from 'pathe'
export const registerTypeTemplates = (resolver: Resolver) => {
addTypeTemplate({
filename: 'types/sanctum.d.ts',
getContents: ({ nuxt }) => {
const { buildDir } = nuxt.options
const getRelativePath = (path: string) => relative(resolve(buildDir, './types'), resolver.resolve(path))
return `// Generated by nuxt-auth-sanctum module
import type { HookResult } from '@nuxt/schema'
import type { FetchContext, FetchResponse } from 'ofetch'
import type { SanctumAppConfig } from '${getRelativePath('./runtime/types/config.ts')}';
import type { SanctumGlobalMiddlewarePageMeta } from '${getRelativePath('./runtime/types/meta.ts')}';
declare module 'nuxt/schema' {
interface AppConfig {
sanctum?: SanctumAppConfig
}
interface AppConfigInput {
sanctum?: SanctumAppConfig
}
}
declare module '@nuxt/schema' {
interface AppConfig {
sanctum?: SanctumAppConfig
}
interface AppConfigInput {
sanctum?: SanctumAppConfig
}
}
declare module '#app' {
interface PageMeta {
/**
* Sanctum global middleware page configuration.
*/
sanctum?: Partial<SanctumGlobalMiddlewarePageMeta>
}
interface RuntimeNuxtHooks {
/**
* Triggers when receiving an error response.
*/
'sanctum:error': (response: FetchResponse<any>) => HookResult
/**
* Triggers when receiving an error on fetch request.
*/
'sanctum:error:request': (context: FetchContext) => HookResult
/**
* Triggers when user has been redirected.
*/
'sanctum:redirect': (path: string) => HookResult
/**
* Triggers when an initial user identity request has been made.
*/
'sanctum:init': () => HookResult
/**
* Triggers when user identity has been refreshed.
*/
'sanctum:refresh': () => HookResult
/**
* Triggers when user successfully logs in.
*/
'sanctum:login': () => HookResult
/**
* Triggers when user successfully logs out.
*/
'sanctum:logout': () => HookResult
}
}
declare module '#app/../pages/runtime/composables' {
interface PageMeta {
/**
* Sanctum global middleware page configuration.
*/
sanctum?: Partial<SanctumGlobalMiddlewarePageMeta>
}
}
export {}`
},
})
}