mulguard 1.1.1 → 1.1.3
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 +34 -0
- package/dist/core/auth/oauth-providers.d.ts +175 -47
- package/dist/core/mulguard/auth-handlers.d.ts +100 -0
- package/dist/core/mulguard/defaults.d.ts +58 -0
- package/dist/core/mulguard/index.d.ts +9 -0
- package/dist/core/mulguard/oauth-handler.d.ts +93 -0
- package/dist/core/mulguard/session-manager.d.ts +94 -0
- package/dist/core/security/index.d.ts +113 -9
- package/dist/core/security/validation.d.ts +231 -33
- package/dist/core/types/auth.d.ts +234 -75
- package/dist/core/types/errors.d.ts +174 -18
- package/dist/core/types/index.d.ts +399 -306
- package/dist/core/utils/logger.d.ts +112 -8
- package/dist/handlers/route.d.ts +59 -5
- package/dist/index/index.js +1 -1
- package/dist/index/index.mjs +1540 -1190
- package/dist/mulguard.d.ts +76 -1
- package/dist/server/helpers.d.ts +3 -3
- package/dist/server/utils.d.ts +3 -3
- package/package.json +1 -1
package/dist/mulguard.d.ts
CHANGED
|
@@ -287,4 +287,79 @@ export interface MulguardInstance {
|
|
|
287
287
|
clearAll(): Promise<void>;
|
|
288
288
|
};
|
|
289
289
|
}
|
|
290
|
-
|
|
290
|
+
/**
|
|
291
|
+
* Create Mulguard instance with custom authentication actions
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ```typescript
|
|
295
|
+
* // lib/auth.ts
|
|
296
|
+
* import { mulguard } from 'mulguard'
|
|
297
|
+
*
|
|
298
|
+
* export const auth = mulguard({
|
|
299
|
+
* session: {
|
|
300
|
+
* cookieName: '__mulguard_session',
|
|
301
|
+
* expiresIn: 60 * 60 * 24 * 7, // 7 days
|
|
302
|
+
* },
|
|
303
|
+
* actions: {
|
|
304
|
+
* signIn: {
|
|
305
|
+
* email: async (credentials) => {
|
|
306
|
+
* // Your custom sign in logic
|
|
307
|
+
* // Connect to your database, validate credentials, etc.
|
|
308
|
+
* const user = await yourDb.findUser(credentials.email)
|
|
309
|
+
* if (!user || !await verifyPassword(credentials.password, user.password)) {
|
|
310
|
+
* return { success: false, error: 'Invalid credentials' }
|
|
311
|
+
* }
|
|
312
|
+
*
|
|
313
|
+
* const session = {
|
|
314
|
+
* user,
|
|
315
|
+
* expiresAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000)
|
|
316
|
+
* }
|
|
317
|
+
*
|
|
318
|
+
* return { success: true, user, session }
|
|
319
|
+
* }
|
|
320
|
+
* },
|
|
321
|
+
* signUp: async (data) => {
|
|
322
|
+
* // Your custom sign up logic
|
|
323
|
+
* const user = await yourDb.createUser(data)
|
|
324
|
+
* return { success: true, user }
|
|
325
|
+
* },
|
|
326
|
+
* signOut: async () => {
|
|
327
|
+
* // Your custom sign out logic
|
|
328
|
+
* await yourDb.invalidateSession()
|
|
329
|
+
* return { success: true }
|
|
330
|
+
* },
|
|
331
|
+
* getSession: async () => {
|
|
332
|
+
* // Your custom session retrieval logic
|
|
333
|
+
* return await yourDb.getSession()
|
|
334
|
+
* }
|
|
335
|
+
* }
|
|
336
|
+
* })
|
|
337
|
+
* ```
|
|
338
|
+
*/
|
|
339
|
+
/**
|
|
340
|
+
* Creates a Mulguard authentication instance.
|
|
341
|
+
*
|
|
342
|
+
* @template TUser - User type (extends base User)
|
|
343
|
+
* @template TSession - Session type (extends base Session)
|
|
344
|
+
* @param config - Mulguard configuration
|
|
345
|
+
* @returns Mulguard instance
|
|
346
|
+
*
|
|
347
|
+
* @example
|
|
348
|
+
* ```typescript
|
|
349
|
+
* const auth = mulguard({
|
|
350
|
+
* actions: {
|
|
351
|
+
* signIn: {
|
|
352
|
+
* email: async (credentials) => {
|
|
353
|
+
* // Your custom sign in logic
|
|
354
|
+
* const user = await db.user.findUnique({ where: { email: credentials.email } })
|
|
355
|
+
* if (!user || !await bcrypt.compare(credentials.password, user.password)) {
|
|
356
|
+
* return { success: false, error: 'Invalid credentials' }
|
|
357
|
+
* }
|
|
358
|
+
* return { success: true, user, session: { user, expiresAt: new Date() } }
|
|
359
|
+
* }
|
|
360
|
+
* }
|
|
361
|
+
* }
|
|
362
|
+
* })
|
|
363
|
+
* ```
|
|
364
|
+
*/
|
|
365
|
+
export declare function mulguard<TUser extends User = User, TSession extends Session<TUser> = Session<TUser>>(config: MulguardConfig<TUser, TSession>): MulguardInstance;
|
package/dist/server/helpers.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { MulguardConfig } from '../core/types';
|
|
|
4
4
|
* Create server-side auth helpers with pre-configured instance
|
|
5
5
|
*/
|
|
6
6
|
export declare function createServerHelpers(_auth: MulguardInstance, _config: MulguardConfig): {
|
|
7
|
-
getSession: () => Promise<import('..').Session | null>;
|
|
8
|
-
requireAuth: (redirectTo?: string) => Promise<import('..').Session
|
|
9
|
-
requireRole: (role: string, redirectTo?: string) => Promise<import('..').Session
|
|
7
|
+
getSession: () => Promise<import('..').Session<import('..').User> | null>;
|
|
8
|
+
requireAuth: (redirectTo?: string) => Promise<import('..').Session<import('..').User>>;
|
|
9
|
+
requireRole: (role: string, redirectTo?: string) => Promise<import('..').Session<import('..').User>>;
|
|
10
10
|
};
|
package/dist/server/utils.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { MulguardInstance } from '../mulguard';
|
|
|
3
3
|
* Create server-side helpers with pre-configured auth instance
|
|
4
4
|
*/
|
|
5
5
|
export declare function createServerUtils(auth: MulguardInstance): {
|
|
6
|
-
getSession: () => Promise<import('..').Session | null>;
|
|
7
|
-
requireAuth: (redirectTo?: string) => Promise<import('..').Session
|
|
8
|
-
requireRole: (role: string, redirectTo?: string) => Promise<import('..').Session
|
|
6
|
+
getSession: () => Promise<import('..').Session<import('..').User> | null>;
|
|
7
|
+
requireAuth: (redirectTo?: string) => Promise<import('..').Session<import('..').User>>;
|
|
8
|
+
requireRole: (role: string, redirectTo?: string) => Promise<import('..').Session<import('..').User>>;
|
|
9
9
|
getCurrentUser: () => Promise<import('..').User | null>;
|
|
10
10
|
};
|