mulguard 1.1.2 → 1.1.4

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.
@@ -287,4 +287,79 @@ export interface MulguardInstance {
287
287
  clearAll(): Promise<void>;
288
288
  };
289
289
  }
290
- export declare function mulguard(config: MulguardConfig): MulguardInstance;
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;
@@ -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
  };
@@ -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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mulguard",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "Mulguard is a modern authentication backend-first library for Next.js",
5
5
  "main": "./dist/index/index.js",
6
6
  "module": "./dist/index/index.mjs",