@devcoffee/nuxt-core 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +407 -84
- package/dist/module.d.mts +295 -156
- package/dist/module.d.ts +300 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +191 -36
- package/dist/runtime/app/composables/useAuthContext.d.ts +26 -0
- package/dist/runtime/app/composables/useAuthContext.js +111 -0
- package/dist/runtime/app/composables/useLogger.d.ts +3 -3
- package/dist/runtime/app/composables/useSessionContext.d.ts +22 -0
- package/dist/runtime/app/composables/useSessionContext.js +5 -0
- package/dist/runtime/app/middleware/authts.d.ts +12 -0
- package/dist/runtime/app/middleware/authts.js +101 -0
- package/dist/runtime/app/pages/authorize.d.vue.ts +3 -0
- package/dist/runtime/app/pages/authorize.vue +32 -0
- package/dist/runtime/app/pages/authorize.vue.d.ts +3 -0
- package/dist/runtime/app/plugins/authts.d.ts +82 -0
- package/dist/runtime/app/plugins/authts.js +91 -0
- package/dist/runtime/app/plugins/formatters.d.ts +29 -0
- package/dist/runtime/app/plugins/formatters.js +101 -0
- package/dist/runtime/app/plugins/locale.d.ts +37 -0
- package/dist/runtime/app/plugins/locale.js +39 -0
- package/dist/runtime/app/plugins/logging.d.ts +24 -16
- package/dist/runtime/app/plugins/logging.js +0 -1
- package/dist/runtime/app/utils/hashing.d.ts +1 -0
- package/dist/runtime/app/utils/hashing.js +3 -0
- package/dist/runtime/server/adapters/http.d.ts +5 -0
- package/dist/runtime/server/adapters/http.js +15 -0
- package/dist/runtime/server/adapters/oidc.d.ts +58 -0
- package/dist/runtime/server/adapters/oidc.js +21 -0
- package/dist/runtime/server/adapters/storage.d.ts +39 -0
- package/dist/runtime/server/adapters/storage.js +14 -0
- package/dist/runtime/server/adapters/utils.d.ts +31 -0
- package/dist/runtime/server/adapters/utils.js +28 -0
- package/dist/runtime/server/composables/useServerLogger.d.ts +3 -2
- package/dist/runtime/server/composables/useServerLogger.js +4 -4
- package/dist/runtime/server/core/crypto.d.ts +70 -0
- package/dist/runtime/server/core/crypto.js +55 -0
- package/dist/runtime/server/core/helpers.d.ts +194 -0
- package/dist/runtime/server/core/helpers.js +355 -0
- package/dist/runtime/server/core/index.d.ts +1 -0
- package/dist/runtime/server/core/index.js +1 -0
- package/dist/runtime/server/core/mutex.d.ts +19 -0
- package/dist/runtime/server/core/mutex.js +39 -0
- package/dist/runtime/server/core/nuxtAuthtsHandler.d.ts +26 -0
- package/dist/runtime/server/core/nuxtAuthtsHandler.js +238 -0
- package/dist/runtime/server/core/nuxtForwardHandler.d.ts +18 -0
- package/dist/runtime/server/core/nuxtForwardHandler.js +60 -0
- package/dist/runtime/server/dev/route/session.d.ts +2 -0
- package/dist/runtime/server/dev/route/session.js +8 -0
- package/dist/runtime/server/plugins/authts.d.ts +11 -0
- package/dist/runtime/server/plugins/authts.js +55 -0
- package/dist/runtime/server/plugins/logging.js +7 -2
- package/dist/runtime/server/tsconfig.json +3 -3
- package/dist/runtime/types/global.env.d.ts +21 -7
- package/dist/runtime/types/nitro.d.ts +7 -2
- package/dist/runtime/types/nuxt.d.ts +28 -8
- package/dist/runtime/utils.d.ts +31 -0
- package/dist/runtime/utils.js +28 -0
- package/dist/types.d.mts +6 -4
- package/package.json +23 -14
- package/dist/runtime/plugin.d.ts +0 -2
- package/dist/runtime/plugin.js +0 -4
package/dist/module.d.ts
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { CookieSerializeOptions } from '#devcoffee-core/runtime/server/adapters/http';
|
|
2
|
+
import { OidcUserInfo } from '#devcoffee-core/runtime/server/adapters/oidc';
|
|
3
|
+
import { ConsolaInstance, LogLevel as LogLevel$1, ConsolaOptions } from 'consola';
|
|
4
|
+
|
|
5
|
+
interface AuthorizedUser {
|
|
6
|
+
id: string
|
|
7
|
+
sub: string
|
|
8
|
+
email: string
|
|
9
|
+
firstName: string
|
|
10
|
+
lastName: string
|
|
11
|
+
locale: string
|
|
12
|
+
language: string
|
|
13
|
+
timezone: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type AuthStatus = 'unauthenticated' | 'authenticated'
|
|
17
|
+
|
|
18
|
+
type AuthData = {
|
|
19
|
+
status: AuthStatus
|
|
20
|
+
tokenSet?: {
|
|
21
|
+
accessToken: string
|
|
22
|
+
tokenType: string
|
|
23
|
+
expiresAt: number
|
|
24
|
+
idToken: string
|
|
25
|
+
refreshToken: string
|
|
26
|
+
scopes: string[]
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type SessionContext<TData = Record<string, unknown>> = {
|
|
31
|
+
id: string
|
|
32
|
+
auth: AuthData
|
|
33
|
+
user: AuthorizedUser
|
|
34
|
+
data: TData
|
|
35
|
+
issuedAt: number
|
|
36
|
+
expiresAt: number
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
type NuxtAuthOptions = {
|
|
40
|
+
/**
|
|
41
|
+
* Default Devcoffee Nuxt AuthTS option callbacks for session and user mapping.
|
|
42
|
+
* These can be overridden by passing custom callbacks to `NuxtAuthtsHandler()`.
|
|
43
|
+
* @since 1.0.0
|
|
44
|
+
*/
|
|
45
|
+
session: (
|
|
46
|
+
session: Omit<SessionContext, 'auth'>,
|
|
47
|
+
auth: SessionContext['auth']
|
|
48
|
+
) => Awaitable<Omit<SessionContext, 'auth' | 'issuedAt' | 'expiresAt'> & { isAuthenticated: boolean }>
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Maps the OpenID Connect user info response to your local user schema.
|
|
52
|
+
*
|
|
53
|
+
* @param user - The raw user info response from the OpenID provider.
|
|
54
|
+
* @param opts - The token response containing access and ID tokens.
|
|
55
|
+
* @returns A normalized user object.
|
|
56
|
+
* @since 1.0.0
|
|
57
|
+
*/
|
|
58
|
+
userInfo: (
|
|
59
|
+
user: AuthorizedUser,
|
|
60
|
+
opts: {
|
|
61
|
+
openidUser?: OidcUserInfo
|
|
62
|
+
tokenSet: Exclude<SessionContext['auth']['tokenSet'], undefined>
|
|
63
|
+
}
|
|
64
|
+
) => Awaitable<AuthorizedUser>
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
type NuxtSessionContext<TData = Record<string, unknown>> = {
|
|
68
|
+
readonly id: string
|
|
69
|
+
readonly isAuthenticated: boolean
|
|
70
|
+
readonly user: AuthorizedUser
|
|
71
|
+
readonly data: TData
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
type NuxtSessionUpdateContext<TData = Record<string, unknown>> = DeepPartial<{
|
|
75
|
+
user: AuthorizedUser
|
|
76
|
+
data: TData
|
|
77
|
+
}>
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* ⚙️ OpenID Connect configuration options.
|
|
81
|
+
*
|
|
82
|
+
* Defines parameters used for client registration, discovery,
|
|
83
|
+
* and token exchange with the OpenID Provider.
|
|
84
|
+
*
|
|
85
|
+
* @since 1.0.0
|
|
86
|
+
*/
|
|
87
|
+
type OpenIdOptions = {
|
|
88
|
+
/** Client ID registered with the OpenID Provider. */
|
|
89
|
+
clientId: string
|
|
90
|
+
|
|
91
|
+
/** Client secret for token exchange (if applicable). */
|
|
92
|
+
clientSecret: string
|
|
93
|
+
|
|
94
|
+
/** Whether to use Proof Key for Code Exchange (PKCE) flow. */
|
|
95
|
+
usePkce: boolean
|
|
96
|
+
|
|
97
|
+
/** Code challenge method, e.g. `S256`. */
|
|
98
|
+
codeChallengeMethod: string
|
|
99
|
+
|
|
100
|
+
/** Scopes requested from the OpenID Provider. */
|
|
101
|
+
scopes: string[]
|
|
102
|
+
|
|
103
|
+
/** Redirect URI used after authorization. */
|
|
104
|
+
redirectUri: string
|
|
105
|
+
|
|
106
|
+
/** The `.well-known/openid-configuration` discovery URL. */
|
|
107
|
+
wellKnownUrl: string
|
|
108
|
+
|
|
109
|
+
/** Whether to automatically fetch user info after login. */
|
|
110
|
+
autoFetchUser: boolean
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* TTL in seconds for caching autoFetchUser results per session.
|
|
114
|
+
* A GET_SESSION within the TTL window does not trigger an OIDC provider call.
|
|
115
|
+
* Only applies when autoFetchUser is true.
|
|
116
|
+
* @default 300
|
|
117
|
+
* @since 1.0.0
|
|
118
|
+
*/
|
|
119
|
+
autoFetchUserTtl: number
|
|
120
|
+
|
|
121
|
+
/** Whether to fetch user info immediately after token grant. */
|
|
122
|
+
fetchUserOnLogin: boolean
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Window in milliseconds before token expiry at which a refresh is triggered.
|
|
126
|
+
* Tokens with expiresAt more than this many milliseconds in the future are
|
|
127
|
+
* considered fresh and the refresh path is skipped entirely.
|
|
128
|
+
* @default 60000
|
|
129
|
+
* @since 1.0.0
|
|
130
|
+
*/
|
|
131
|
+
tokenRefreshBufferMs: number
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* When `true`, the token refresh mutex uses an atomic Redis NX write
|
|
135
|
+
* (`SET key value NX EX ttl`) via the IORedis native client accessor for
|
|
136
|
+
* true distributed exclusion across multiple server instances. When `false`
|
|
137
|
+
* (default), the existing optimistic lock (`hasItem` + `setItem`) is used.
|
|
138
|
+
*
|
|
139
|
+
* @remarks Only effective when the Nitro `cache` storage mount is backed by
|
|
140
|
+
* a Redis driver. Setting `true` with a non-Redis backend falls through to
|
|
141
|
+
* the optimistic path silently.
|
|
142
|
+
*
|
|
143
|
+
* @default false
|
|
144
|
+
* @since 1.0.0
|
|
145
|
+
*/
|
|
146
|
+
distributedLock?: boolean
|
|
147
|
+
|
|
148
|
+
/** Cache configuration for storing OpenID metadata. */
|
|
149
|
+
cache: {
|
|
150
|
+
/** Cache key prefix for the metadata store. */
|
|
151
|
+
prefix: string
|
|
152
|
+
/** Expiry time in seconds for cached metadata. */
|
|
153
|
+
expires: number
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* 🍪 Session management configuration.
|
|
159
|
+
*
|
|
160
|
+
* Defines session storage, expiration, and cookie behavior
|
|
161
|
+
* for authentication session tracking.
|
|
162
|
+
*
|
|
163
|
+
* @since 1.0.0
|
|
164
|
+
*/
|
|
165
|
+
type SessionsOptions = {
|
|
166
|
+
/** Cookie name mappings used by the session handler. */
|
|
167
|
+
names: {
|
|
168
|
+
/** PKCE verifier cookie name. */
|
|
169
|
+
pkce: string
|
|
170
|
+
/** State cookie name. */
|
|
171
|
+
state: string
|
|
172
|
+
/** Session ID cookie name. */
|
|
173
|
+
sessionId: string
|
|
174
|
+
/** Redirect URL cookie name. */
|
|
175
|
+
redirectUrl: string
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
storage: {
|
|
179
|
+
name: string
|
|
180
|
+
|
|
181
|
+
/** Key prefix for session data in the storage backend. */
|
|
182
|
+
prefix: string
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Session lifetime in seconds. */
|
|
186
|
+
expiresIn: number
|
|
187
|
+
|
|
188
|
+
/** Options for how session cookies are serialized. */
|
|
189
|
+
cookieOpts: CookieSerializeOptions
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Secret used to HMAC-sign session ID cookies and derive the AES-256-GCM key
|
|
193
|
+
* for tokenSet encryption. When empty, signing and encryption are skipped.
|
|
194
|
+
* @since 1.0.0
|
|
195
|
+
*/
|
|
196
|
+
secret?: string
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* 🔐 Authentication behavior configuration.
|
|
201
|
+
*
|
|
202
|
+
* Defines default redirect paths and URIs used for login/logout flow.
|
|
203
|
+
*
|
|
204
|
+
* @since 1.0.0
|
|
205
|
+
*/
|
|
206
|
+
type AuthOptions = {
|
|
207
|
+
/** Path to the login page. */
|
|
208
|
+
loginUri: string
|
|
209
|
+
|
|
210
|
+
/** Default redirect URI after successful login. */
|
|
211
|
+
defaultLoginRedirectUri: string
|
|
212
|
+
|
|
213
|
+
/** Default redirect URI after logout. */
|
|
214
|
+
defaultLogoutRedirectUri: string
|
|
215
|
+
|
|
216
|
+
/** Default anonymous user object. */
|
|
217
|
+
anonymousUser: AuthorizedUser
|
|
218
|
+
|
|
219
|
+
ignoreRegexPatterns: RegExp[]
|
|
220
|
+
|
|
221
|
+
ignoreRegexPatternsDev: RegExp[]
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* 🧩 Main configuration interface for the Nuxt AuthTS module.
|
|
226
|
+
*
|
|
227
|
+
* Combines OpenID Connect, session, and general authentication options.
|
|
228
|
+
*
|
|
229
|
+
* @since 1.0.0
|
|
230
|
+
*/
|
|
231
|
+
type AuthtsModuleOptions = {
|
|
232
|
+
/** Enable or disable the module */
|
|
233
|
+
enabled: boolean
|
|
234
|
+
openid: OpenIdOptions
|
|
235
|
+
sessions: SessionsOptions
|
|
236
|
+
auth: AuthOptions
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
interface AuthtsMiddlewareMeta {
|
|
240
|
+
/** Require authentication to access */
|
|
241
|
+
required?: boolean
|
|
242
|
+
|
|
243
|
+
/** Only accessible if unauthenticated (login/register pages) */
|
|
244
|
+
unauthenticatedOnly?: boolean
|
|
245
|
+
|
|
246
|
+
/** Restrict access to these roles */
|
|
247
|
+
roles?: string[]
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
type CoreLogLevel = LogLevel$1
|
|
251
|
+
type CoreLogInstance = ConsolaInstance
|
|
252
|
+
|
|
253
|
+
type LoggingOptions = {
|
|
254
|
+
tag: string
|
|
255
|
+
level: CoreLogLevel
|
|
256
|
+
} & DeepPartial<Pick<ConsolaOptions, 'throttle' | 'throttleMin' | 'formatOptions'>>
|
|
257
|
+
|
|
258
|
+
type NuxtCoreLogging = {
|
|
259
|
+
getLogger: (opts?: { tag?: string; level?: LogLevel }) => CoreLogInstance
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
type LoggingModuleOptions = {
|
|
263
|
+
server: LoggingOptions
|
|
264
|
+
ssr: LoggingOptions
|
|
265
|
+
client: LoggingOptions
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
type ModuleOptions = {
|
|
269
|
+
defaultLocale: string
|
|
270
|
+
defaultLanguage: string
|
|
271
|
+
defaultTimeZone: string
|
|
272
|
+
logging: LoggingModuleOptions
|
|
273
|
+
authts: AuthtsModuleOptions
|
|
274
|
+
formatters: GenericType
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
type ModulePublicRuntimeConfig = Pick<ModuleOptions, 'defaultLocale' | 'defaultTimeZone' | 'defaultLanguage'> & {
|
|
278
|
+
logging: ModuleOptions['logging']['client']
|
|
279
|
+
|
|
280
|
+
authts: Pick<
|
|
281
|
+
AuthtsModuleOptions['auth'],
|
|
282
|
+
| 'loginUri'
|
|
283
|
+
| 'defaultLoginRedirectUri'
|
|
284
|
+
| 'defaultLogoutRedirectUri'
|
|
285
|
+
| 'ignoreRegexPatterns'
|
|
286
|
+
| 'ignoreRegexPatternsDev'
|
|
287
|
+
> &
|
|
288
|
+
Pick<AuthtsModuleOptions['openid'], 'redirectUri'> & {
|
|
289
|
+
enabled: boolean
|
|
290
|
+
redirectCookie: string
|
|
291
|
+
sessionCookie: string
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
type InputModuleOptions = DeepPartial<ModuleOptions>
|
|
296
|
+
|
|
297
|
+
declare const _default: any;
|
|
298
|
+
|
|
299
|
+
export { _default as default };
|
|
300
|
+
export type { AuthData, AuthorizedUser, AuthtsMiddlewareMeta, AuthtsModuleOptions, CoreLogInstance, CoreLogLevel, InputModuleOptions, LoggingModuleOptions, LoggingOptions, ModuleOptions, ModulePublicRuntimeConfig, NuxtAuthOptions, NuxtCoreLogging, NuxtSessionContext, NuxtSessionUpdateContext, SessionContext };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,31 +1,118 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { addCustomTab } from '@nuxt/devtools-kit';
|
|
2
|
+
import { defineNuxtModule, useLogger, createResolver, addServerImports, addServerImportsDir, addServerPlugin, addImportsDir, addPlugin, addRouteMiddleware, addTemplate, addServerHandler } from '@nuxt/kit';
|
|
3
|
+
import { deepMerge, pick } from '../dist/runtime/utils.js';
|
|
3
4
|
|
|
4
|
-
const version = "1.0
|
|
5
|
+
const version = "1.1.0";
|
|
5
6
|
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const defaultLocale = "vi-VN";
|
|
8
|
+
const defaultLanguage = "vi";
|
|
9
|
+
const defaultTimeZone = "Asia/Ho_Chi_Minh";
|
|
10
|
+
const loggingDefaults = {
|
|
11
|
+
server: {
|
|
12
|
+
tag: "server",
|
|
13
|
+
level: 2
|
|
14
|
+
},
|
|
15
|
+
ssr: {
|
|
16
|
+
tag: "app-ssr",
|
|
17
|
+
level: 2
|
|
18
|
+
},
|
|
19
|
+
client: {
|
|
20
|
+
tag: "app-client",
|
|
21
|
+
level: 2
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const authtsDefaults = {
|
|
25
|
+
enabled: true,
|
|
26
|
+
openid: {
|
|
27
|
+
cache: {
|
|
28
|
+
prefix: "oidc-server-meta",
|
|
29
|
+
expires: 60 * 60 * 24
|
|
11
30
|
},
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
31
|
+
wellKnownUrl: "",
|
|
32
|
+
clientId: "",
|
|
33
|
+
clientSecret: "",
|
|
34
|
+
redirectUri: "/authorize",
|
|
35
|
+
scopes: [],
|
|
36
|
+
usePkce: true,
|
|
37
|
+
autoFetchUser: true,
|
|
38
|
+
autoFetchUserTtl: 300,
|
|
39
|
+
fetchUserOnLogin: true,
|
|
40
|
+
tokenRefreshBufferMs: 6e4,
|
|
41
|
+
distributedLock: false,
|
|
42
|
+
codeChallengeMethod: "S256"
|
|
43
|
+
},
|
|
44
|
+
sessions: {
|
|
45
|
+
names: {
|
|
46
|
+
sessionId: "auths.ssid",
|
|
47
|
+
redirectUrl: "auths.redirect",
|
|
48
|
+
state: "auths.state",
|
|
49
|
+
pkce: "auths.pkce"
|
|
15
50
|
},
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
51
|
+
storage: { name: "sessions", prefix: "session" },
|
|
52
|
+
expiresIn: 60 * 60 * 24 * 6,
|
|
53
|
+
// 6 days
|
|
54
|
+
cookieOpts: {
|
|
55
|
+
path: "/",
|
|
56
|
+
sameSite: "lax",
|
|
57
|
+
httpOnly: true,
|
|
58
|
+
secure: process.env.NODE_ENV === "production"
|
|
59
|
+
},
|
|
60
|
+
secret: ""
|
|
61
|
+
},
|
|
62
|
+
auth: {
|
|
63
|
+
loginUri: "/login",
|
|
64
|
+
defaultLoginRedirectUri: "/",
|
|
65
|
+
defaultLogoutRedirectUri: "/login",
|
|
66
|
+
anonymousUser: {
|
|
67
|
+
id: "anonymous",
|
|
68
|
+
email: "",
|
|
69
|
+
sub: "anonymous",
|
|
70
|
+
firstName: "Anonymous",
|
|
71
|
+
lastName: "User",
|
|
72
|
+
locale: defaultLocale,
|
|
73
|
+
language: defaultLanguage,
|
|
74
|
+
timezone: defaultTimeZone
|
|
75
|
+
},
|
|
76
|
+
ignoreRegexPatterns: [],
|
|
77
|
+
ignoreRegexPatternsDev: []
|
|
20
78
|
}
|
|
21
79
|
};
|
|
22
80
|
function normalizedModuleOptions(...inputOpts) {
|
|
23
|
-
return
|
|
81
|
+
return deepMerge(
|
|
82
|
+
{
|
|
83
|
+
defaultLocale,
|
|
84
|
+
defaultLanguage,
|
|
85
|
+
defaultTimeZone,
|
|
86
|
+
logging: loggingDefaults,
|
|
87
|
+
authts: authtsDefaults
|
|
88
|
+
},
|
|
89
|
+
...inputOpts
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
function normalizePublicRuntimeConfig(inputOpts) {
|
|
93
|
+
const { enabled } = inputOpts.authts;
|
|
94
|
+
const { loginUri, defaultLoginRedirectUri, defaultLogoutRedirectUri, ignoreRegexPatterns, ignoreRegexPatternsDev } = inputOpts.authts.auth;
|
|
95
|
+
const { redirectUri } = inputOpts.authts.openid;
|
|
96
|
+
const { redirectUrl: redirectCookie, sessionId: sessionCookie } = inputOpts.authts.sessions.names;
|
|
97
|
+
return {
|
|
98
|
+
logging: { ...inputOpts.logging.client },
|
|
99
|
+
authts: {
|
|
100
|
+
enabled,
|
|
101
|
+
loginUri,
|
|
102
|
+
redirectUri,
|
|
103
|
+
sessionCookie,
|
|
104
|
+
redirectCookie,
|
|
105
|
+
defaultLoginRedirectUri,
|
|
106
|
+
defaultLogoutRedirectUri,
|
|
107
|
+
ignoreRegexPatterns,
|
|
108
|
+
ignoreRegexPatternsDev
|
|
109
|
+
},
|
|
110
|
+
...pick(inputOpts, ["defaultLocale", "defaultTimeZone", "defaultLanguage"])
|
|
111
|
+
};
|
|
24
112
|
}
|
|
25
113
|
|
|
26
114
|
const moduleName = "nuxt-core";
|
|
27
115
|
const configKey = "nuxtCore";
|
|
28
|
-
const logger = useLogger(moduleName);
|
|
29
116
|
const module = defineNuxtModule({
|
|
30
117
|
meta: {
|
|
31
118
|
name: moduleName,
|
|
@@ -35,40 +122,108 @@ const module = defineNuxtModule({
|
|
|
35
122
|
nuxt: "^4.0.0"
|
|
36
123
|
}
|
|
37
124
|
},
|
|
38
|
-
|
|
39
|
-
|
|
125
|
+
defaults: (_nuxt) => {
|
|
126
|
+
return normalizedModuleOptions({}, (_nuxt.options.runtimeConfig || {})[configKey] || {});
|
|
127
|
+
},
|
|
40
128
|
setup(_options, _nuxt) {
|
|
129
|
+
const logger = useLogger();
|
|
41
130
|
const resolver = createResolver(import.meta.url);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
[configKey]
|
|
131
|
+
const resolvedOptions = normalizedModuleOptions(
|
|
132
|
+
{},
|
|
133
|
+
_options,
|
|
134
|
+
(_nuxt.options.runtimeConfig || {})[configKey] || {}
|
|
135
|
+
);
|
|
136
|
+
_nuxt.options.runtimeConfig = deepMerge(_nuxt.options.runtimeConfig || {}, {
|
|
137
|
+
[configKey]: resolvedOptions,
|
|
46
138
|
public: {
|
|
47
|
-
[configKey]:
|
|
139
|
+
[configKey]: normalizePublicRuntimeConfig(resolvedOptions)
|
|
48
140
|
}
|
|
49
141
|
});
|
|
50
|
-
_nuxt.options.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
142
|
+
_nuxt.options.alias["#devcoffee-core"] = resolver.resolve("./runtime");
|
|
143
|
+
addServerImports([
|
|
144
|
+
{
|
|
145
|
+
from: resolver.resolve("./runtime/server/core/nuxtAuthtsHandler"),
|
|
146
|
+
name: "default",
|
|
147
|
+
as: "NuxtAuthtsHandler"
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
from: resolver.resolve("./runtime/server/core/nuxtForwardHandler"),
|
|
151
|
+
name: "default",
|
|
152
|
+
as: "NuxtForwardRequestHandler"
|
|
153
|
+
}
|
|
154
|
+
]);
|
|
56
155
|
addServerImportsDir(resolver.resolve("./runtime/server/composables"));
|
|
57
156
|
addServerPlugin(resolver.resolve("./runtime/server/plugins/logging"));
|
|
58
|
-
|
|
157
|
+
addServerPlugin(resolver.resolve("./runtime/server/plugins/authts"));
|
|
158
|
+
addImportsDir([resolver.resolve("./runtime/app/composables"), resolver.resolve("./runtime/app/utils")]);
|
|
159
|
+
addPlugin({
|
|
160
|
+
mode: "all",
|
|
161
|
+
name: "authts",
|
|
162
|
+
src: resolver.resolve("./runtime/app/plugins/authts")
|
|
163
|
+
});
|
|
59
164
|
addPlugin({
|
|
60
165
|
mode: "all",
|
|
61
166
|
name: "devcoffee-nuxt-core-logging",
|
|
62
167
|
src: resolver.resolve("./runtime/app/plugins/logging")
|
|
63
168
|
});
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
169
|
+
addPlugin(
|
|
170
|
+
{
|
|
171
|
+
mode: "all",
|
|
172
|
+
name: "core-locale",
|
|
173
|
+
src: resolver.resolve("./runtime/app/plugins/locale")
|
|
174
|
+
},
|
|
175
|
+
{ append: true }
|
|
176
|
+
);
|
|
177
|
+
addPlugin(
|
|
178
|
+
{
|
|
179
|
+
mode: "all",
|
|
180
|
+
name: "core-formatters",
|
|
181
|
+
src: resolver.resolve("./runtime/app/plugins/formatters")
|
|
182
|
+
},
|
|
183
|
+
{ append: true }
|
|
184
|
+
);
|
|
185
|
+
addRouteMiddleware([{ name: "authts", path: resolver.resolve("./runtime/app/middleware/authts"), global: true }], {
|
|
186
|
+
prepend: true
|
|
187
|
+
});
|
|
188
|
+
const globalTypes = addTemplate({
|
|
189
|
+
filename: "types/devcoffee-global.d.ts",
|
|
190
|
+
src: resolver.resolve("./runtime/types/global.env.d.ts")
|
|
191
|
+
});
|
|
192
|
+
_nuxt.options.nitro = deepMerge(_nuxt.options.nitro || {}, {
|
|
193
|
+
typescript: {
|
|
194
|
+
tsConfig: {
|
|
195
|
+
include: [globalTypes.dst]
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
const nuxtTypes = addTemplate({
|
|
200
|
+
filename: "types/devcoffee-nuxt-core.d.ts",
|
|
201
|
+
src: resolver.resolve("./runtime/types/nuxt.d.ts")
|
|
202
|
+
});
|
|
203
|
+
const nitroTypes = addTemplate({
|
|
204
|
+
filename: "types/devcoffee-nitro-core.d.ts",
|
|
205
|
+
src: resolver.resolve("./runtime/types/nitro.d.ts")
|
|
67
206
|
});
|
|
68
207
|
_nuxt.hook("prepare:types", (opts) => {
|
|
69
|
-
opts.references.push({ path:
|
|
70
|
-
opts.references.push({ path:
|
|
208
|
+
opts.references.push({ path: globalTypes.dst });
|
|
209
|
+
opts.references.push({ path: nuxtTypes.dst });
|
|
210
|
+
opts.references.push({ path: nitroTypes.dst });
|
|
71
211
|
});
|
|
212
|
+
if (_nuxt.options?.devtools) {
|
|
213
|
+
addCustomTab({
|
|
214
|
+
name: "devcoffee-core-session",
|
|
215
|
+
title: "Devcoffee Session",
|
|
216
|
+
icon: "carbon:apps",
|
|
217
|
+
view: {
|
|
218
|
+
type: "iframe",
|
|
219
|
+
src: "/__devcoffee_core_session_devtools__"
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
addServerHandler({
|
|
223
|
+
route: "/__devcoffee_core_session_devtools__",
|
|
224
|
+
handler: resolver.resolve("./runtime/server/dev/route/session")
|
|
225
|
+
});
|
|
226
|
+
}
|
|
72
227
|
logger.success("`%s` setup finished", moduleName);
|
|
73
228
|
}
|
|
74
229
|
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🧩 Provides reactive authentication state and actions for user login and authorization.
|
|
3
|
+
*
|
|
4
|
+
* This composable integrates with your Nuxt authentication system (`/api/_auth/*` endpoints)
|
|
5
|
+
* and session context to perform login, handle token exchanges, and update user session state.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const { login, authorize, isAuthenticated, processing } = useAuthContext()
|
|
10
|
+
*
|
|
11
|
+
* async function handleLogin() {
|
|
12
|
+
* await login('/dashboard')
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
* @param {string} [initiator] - Optional initiator for logging purposes.
|
|
16
|
+
* @since 1.0.0
|
|
17
|
+
*/
|
|
18
|
+
export declare function useAuthContext(initiator?: string): {
|
|
19
|
+
user: any;
|
|
20
|
+
session: any;
|
|
21
|
+
processing: any;
|
|
22
|
+
isAuthenticated: any;
|
|
23
|
+
login: (redirectTo?: string) => Promise<void>;
|
|
24
|
+
authorize: (parameters: URLSearchParams) => Promise<void>;
|
|
25
|
+
logout: () => Promise<void>;
|
|
26
|
+
};
|