@adonisjs/auth 9.0.0-8 → 9.0.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.
Files changed (125) hide show
  1. package/build/chunk-3HZHOWKL.js +8 -0
  2. package/build/chunk-3HZHOWKL.js.map +1 -0
  3. package/build/chunk-52DVKHJR.js +246 -0
  4. package/build/chunk-52DVKHJR.js.map +1 -0
  5. package/build/chunk-BHB55PBJ.js +197 -0
  6. package/build/chunk-BHB55PBJ.js.map +1 -0
  7. package/build/chunk-CZCFTIBB.js +21 -0
  8. package/build/chunk-CZCFTIBB.js.map +1 -0
  9. package/build/index.d.ts +7 -6
  10. package/build/index.js +146 -15
  11. package/build/index.js.map +1 -0
  12. package/build/modules/access_tokens_guard/access_token.d.ts +137 -0
  13. package/build/modules/access_tokens_guard/crc32.d.ts +16 -0
  14. package/build/modules/access_tokens_guard/define_config.d.ts +17 -0
  15. package/build/modules/access_tokens_guard/guard.d.ts +81 -0
  16. package/build/modules/access_tokens_guard/main.d.ts +5 -0
  17. package/build/modules/access_tokens_guard/main.js +929 -0
  18. package/build/modules/access_tokens_guard/main.js.map +1 -0
  19. package/build/modules/access_tokens_guard/token_providers/db.d.ts +76 -0
  20. package/build/modules/access_tokens_guard/types.d.ts +208 -0
  21. package/build/modules/access_tokens_guard/types.js +1 -0
  22. package/build/modules/access_tokens_guard/types.js.map +1 -0
  23. package/build/modules/access_tokens_guard/user_providers/lucid.d.ts +53 -0
  24. package/build/modules/session_guard/define_config.d.ts +17 -0
  25. package/build/modules/session_guard/guard.d.ts +98 -0
  26. package/build/modules/session_guard/main.d.ts +5 -0
  27. package/build/modules/session_guard/main.js +741 -0
  28. package/build/modules/session_guard/main.js.map +1 -0
  29. package/build/modules/session_guard/remember_me_token.d.ts +88 -0
  30. package/build/modules/session_guard/token_providers/db.d.ts +69 -0
  31. package/build/modules/session_guard/types.d.ts +243 -0
  32. package/build/modules/session_guard/types.js +1 -0
  33. package/build/modules/session_guard/types.js.map +1 -0
  34. package/build/modules/session_guard/user_providers/lucid.d.ts +57 -0
  35. package/build/providers/auth_provider.d.ts +1 -1
  36. package/build/providers/auth_provider.js +31 -27
  37. package/build/providers/auth_provider.js.map +1 -0
  38. package/build/services/auth.d.ts +1 -1
  39. package/build/services/auth.js +10 -15
  40. package/build/services/auth.js.map +1 -0
  41. package/build/src/{auth/auth_manager.d.ts → auth_manager.d.ts} +8 -3
  42. package/build/src/authenticator.d.ts +81 -0
  43. package/build/src/{auth/authenticator_client.d.ts → authenticator_client.d.ts} +4 -4
  44. package/build/src/{auth/define_config.d.ts → define_config.d.ts} +0 -10
  45. package/build/src/errors.d.ts +105 -0
  46. package/build/src/{auth/middleware → middleware}/initialize_auth_middleware.d.ts +3 -2
  47. package/build/src/middleware/initialize_auth_middleware.js +17 -0
  48. package/build/src/middleware/initialize_auth_middleware.js.map +1 -0
  49. package/build/src/mixins/with_auth_finder.d.ts +156 -0
  50. package/build/src/{auth/plugins → plugins}/japa/api_client.d.ts +8 -8
  51. package/build/src/plugins/japa/api_client.js +59 -0
  52. package/build/src/plugins/japa/api_client.js.map +1 -0
  53. package/build/src/{auth/plugins → plugins}/japa/browser_client.d.ts +10 -7
  54. package/build/src/plugins/japa/browser_client.js +67 -0
  55. package/build/src/plugins/japa/browser_client.js.map +1 -0
  56. package/build/src/{auth/types.d.ts → types.d.ts} +31 -26
  57. package/build/src/types.js +1 -0
  58. package/build/src/types.js.map +1 -0
  59. package/package.json +90 -70
  60. package/build/configure.js +0 -47
  61. package/build/factories/basic_auth_guard_factory.d.ts +0 -12
  62. package/build/factories/basic_auth_guard_factory.js +0 -22
  63. package/build/factories/database_token_factory.d.ts +0 -36
  64. package/build/factories/database_token_factory.js +0 -54
  65. package/build/factories/database_user_provider.d.ts +0 -14
  66. package/build/factories/database_user_provider.js +0 -27
  67. package/build/factories/lucid_user_provider.d.ts +0 -28
  68. package/build/factories/lucid_user_provider.js +0 -68
  69. package/build/factories/main.d.ts +0 -4
  70. package/build/factories/main.js +0 -12
  71. package/build/factories/session_guard_factory.d.ts +0 -13
  72. package/build/factories/session_guard_factory.js +0 -24
  73. package/build/src/auth/auth_manager.js +0 -41
  74. package/build/src/auth/authenticator.d.ts +0 -63
  75. package/build/src/auth/authenticator.js +0 -129
  76. package/build/src/auth/authenticator_client.js +0 -59
  77. package/build/src/auth/debug.js +0 -10
  78. package/build/src/auth/define_config.js +0 -54
  79. package/build/src/auth/errors.d.ts +0 -90
  80. package/build/src/auth/errors.js +0 -201
  81. package/build/src/auth/middleware/initialize_auth_middleware.js +0 -25
  82. package/build/src/auth/plugins/japa/api_client.js +0 -63
  83. package/build/src/auth/plugins/japa/browser_client.js +0 -42
  84. package/build/src/auth/symbols.js +0 -17
  85. package/build/src/auth/types.js +0 -9
  86. package/build/src/auth/user_providers/main.d.ts +0 -15
  87. package/build/src/auth/user_providers/main.js +0 -22
  88. package/build/src/core/guard_user.d.ts +0 -26
  89. package/build/src/core/guard_user.js +0 -29
  90. package/build/src/core/token.d.ts +0 -89
  91. package/build/src/core/token.js +0 -114
  92. package/build/src/core/token_providers/database.d.ts +0 -77
  93. package/build/src/core/token_providers/database.js +0 -113
  94. package/build/src/core/types.d.ts +0 -178
  95. package/build/src/core/types.js +0 -9
  96. package/build/src/core/user_providers/database.d.ts +0 -78
  97. package/build/src/core/user_providers/database.js +0 -117
  98. package/build/src/core/user_providers/lucid.d.ts +0 -61
  99. package/build/src/core/user_providers/lucid.js +0 -122
  100. package/build/src/guards/basic_auth/define_config.d.ts +0 -16
  101. package/build/src/guards/basic_auth/define_config.js +0 -38
  102. package/build/src/guards/basic_auth/guard.d.ts +0 -70
  103. package/build/src/guards/basic_auth/guard.js +0 -190
  104. package/build/src/guards/basic_auth/main.d.ts +0 -2
  105. package/build/src/guards/basic_auth/main.js +0 -10
  106. package/build/src/guards/basic_auth/types.d.ts +0 -35
  107. package/build/src/guards/basic_auth/types.js +0 -9
  108. package/build/src/guards/session/define_config.d.ts +0 -23
  109. package/build/src/guards/session/define_config.js +0 -56
  110. package/build/src/guards/session/guard.d.ts +0 -123
  111. package/build/src/guards/session/guard.js +0 -510
  112. package/build/src/guards/session/main.d.ts +0 -3
  113. package/build/src/guards/session/main.js +0 -11
  114. package/build/src/guards/session/token.d.ts +0 -57
  115. package/build/src/guards/session/token.js +0 -58
  116. package/build/src/guards/session/token_providers/main.d.ts +0 -33
  117. package/build/src/guards/session/token_providers/main.js +0 -42
  118. package/build/src/guards/session/types.d.ts +0 -104
  119. package/build/src/guards/session/types.js +0 -9
  120. package/build/stubs/main.d.ts +0 -1
  121. package/build/stubs/main.js +0 -10
  122. package/build/stubs/middleware/auth_middleware.stub +0 -30
  123. package/build/stubs/middleware/guest_middleware.stub +0 -36
  124. /package/build/src/{auth/debug.d.ts → debug.d.ts} +0 -0
  125. /package/build/src/{auth/symbols.d.ts → symbols.d.ts} +0 -0
@@ -1,17 +1,12 @@
1
- /*
2
- * @adonisjs/auth
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import app from '@adonisjs/core/services/app';
10
- let auth;
11
- /**
12
- * Returns a singleton instance of the Auth manager class
13
- */
1
+ import "../chunk-CZCFTIBB.js";
2
+
3
+ // services/auth.ts
4
+ import app from "@adonisjs/core/services/app";
5
+ var auth;
14
6
  await app.booted(async () => {
15
- auth = await app.container.make('auth.manager');
7
+ auth = await app.container.make("auth.manager");
16
8
  });
17
- export { auth as default };
9
+ export {
10
+ auth as default
11
+ };
12
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../services/auth.ts"],"sourcesContent":["/*\n * @adonisjs/auth\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport app from '@adonisjs/core/services/app'\nimport { AuthService } from '../src/types.js'\n\nlet auth: AuthService\n\n/**\n * Returns a singleton instance of the Auth manager class\n */\nawait app.booted(async () => {\n auth = await app.container.make('auth.manager')\n})\n\nexport { auth as default }\n"],"mappings":";;;AASA,OAAO,SAAS;AAGhB,IAAI;AAKJ,MAAM,IAAI,OAAO,YAAY;AAC3B,SAAO,MAAM,IAAI,UAAU,KAAK,cAAc;AAChD,CAAC;","names":[]}
@@ -7,7 +7,10 @@ import { AuthenticatorClient } from './authenticator_client.js';
7
7
  * guards from the config
8
8
  */
9
9
  export declare class AuthManager<KnownGuards extends Record<string, GuardFactory>> {
10
- #private;
10
+ config: {
11
+ default: keyof KnownGuards;
12
+ guards: KnownGuards;
13
+ };
11
14
  /**
12
15
  * Name of the default guard
13
16
  */
@@ -17,11 +20,13 @@ export declare class AuthManager<KnownGuards extends Record<string, GuardFactory
17
20
  guards: KnownGuards;
18
21
  });
19
22
  /**
20
- * Create an authenticator for a given HTTP request
23
+ * Create an authenticator for a given HTTP request. The authenticator
24
+ * is used to authenticated in incoming HTTP request
21
25
  */
22
26
  createAuthenticator(ctx: HttpContext): Authenticator<KnownGuards>;
23
27
  /**
24
- * Creates an instance of the authenticator client
28
+ * Creates an instance of the authenticator client. The client is
29
+ * used to setup authentication state during testing.
25
30
  */
26
31
  createAuthenticatorClient(): AuthenticatorClient<KnownGuards>;
27
32
  }
@@ -0,0 +1,81 @@
1
+ import type { HttpContext } from '@adonisjs/core/http';
2
+ import type { GuardFactory } from './types.js';
3
+ /**
4
+ * Authenticator is used to authenticate incoming HTTP requests
5
+ * using one or more known guards.
6
+ */
7
+ export declare class Authenticator<KnownGuards extends Record<string, GuardFactory>> {
8
+ #private;
9
+ /**
10
+ * Name of the default guard
11
+ */
12
+ get defaultGuard(): keyof KnownGuards;
13
+ /**
14
+ * Reference to the guard using which the current
15
+ * request has been authenticated.
16
+ */
17
+ get authenticatedViaGuard(): keyof KnownGuards | undefined;
18
+ /**
19
+ * A boolean to know if the current request has been authenticated. The
20
+ * property returns false when "authenticate" or "authenticateUsing"
21
+ * methods are not used.
22
+ */
23
+ get isAuthenticated(): boolean;
24
+ /**
25
+ * Reference to the currently authenticated user. The property returns
26
+ * undefined when "authenticate" or "authenticateUsing" methods are
27
+ * not used.
28
+ */
29
+ get user(): {
30
+ [K in keyof KnownGuards]: ReturnType<KnownGuards[K]>['user'];
31
+ }[keyof KnownGuards];
32
+ /**
33
+ * Whether or not the authentication has been attempted during
34
+ * the current request. The property returns false when the
35
+ * "authenticate" or "authenticateUsing" methods are not
36
+ * used.
37
+ */
38
+ get authenticationAttempted(): boolean;
39
+ constructor(ctx: HttpContext, config: {
40
+ default: keyof KnownGuards;
41
+ guards: KnownGuards;
42
+ });
43
+ /**
44
+ * Returns an instance of the logged-in user or throws an
45
+ * exception
46
+ */
47
+ getUserOrFail(): {
48
+ [K in keyof KnownGuards]: ReturnType<ReturnType<KnownGuards[K]>['getUserOrFail']>;
49
+ }[keyof KnownGuards];
50
+ /**
51
+ * Returns an instance of a known guard. Guards instances are
52
+ * cached during the lifecycle of an HTTP request.
53
+ */
54
+ use<Guard extends keyof KnownGuards>(guard?: Guard): ReturnType<KnownGuards[Guard]>;
55
+ /**
56
+ * Authenticate current request using the default guard. Calling this
57
+ * method multiple times triggers multiple authentication with the
58
+ * guard.
59
+ */
60
+ authenticate(): Promise<{ [K in keyof KnownGuards]: ReturnType<ReturnType<KnownGuards[K]>["getUserOrFail"]>; }[keyof KnownGuards]>;
61
+ /**
62
+ * Silently attempt to authenticate the request using the default
63
+ * guard. Calling this method multiple times triggers multiple
64
+ * authentication with the guard.
65
+ */
66
+ check(): Promise<boolean>;
67
+ /**
68
+ * Authenticate the request using all of the mentioned guards
69
+ * or the default guard.
70
+ *
71
+ * The authentication process will stop after any of the mentioned
72
+ * guards is able to authenticate the request successfully.
73
+ *
74
+ * Otherwise, "E_UNAUTHORIZED_ACCESS" will be raised.
75
+ */
76
+ authenticateUsing(guards?: (keyof KnownGuards)[], options?: {
77
+ loginRoute?: string;
78
+ }): Promise<{
79
+ [K in keyof KnownGuards]: ReturnType<ReturnType<KnownGuards[K]>['getUserOrFail']>;
80
+ }[keyof KnownGuards]>;
81
+ }
@@ -1,9 +1,9 @@
1
1
  import type { GuardFactory } from './types.js';
2
2
  /**
3
- * Authenticator client is used to create guard instances for
4
- * testing. It passes a fake HTTPContext to the guards, so
5
- * make sure to not call server side APIs that might be
6
- * relying on a real HTTPContext instance
3
+ * Authenticator client is used to create guard instances for testing.
4
+ * It passes a fake HTTPContext to the guards, so make sure to not
5
+ * call server side APIs that might be relying on a real
6
+ * HTTPContext instance.
7
7
  */
8
8
  export declare class AuthenticatorClient<KnownGuards extends Record<string, GuardFactory>> {
9
9
  #private;
@@ -1,7 +1,5 @@
1
1
  import type { ConfigProvider } from '@adonisjs/core/types';
2
2
  import type { GuardConfigProvider, GuardFactory } from './types.js';
3
- import type { LucidUserProvider, DatabaseUserProvider } from './user_providers/main.js';
4
- import type { LucidAuthenticatable, LucidUserProviderOptions, DatabaseUserProviderOptions } from '../core/types.js';
5
3
  /**
6
4
  * Config resolved by the "defineConfig" method
7
5
  */
@@ -20,11 +18,3 @@ export declare function defineConfig<KnownGuards extends Record<string, GuardFac
20
18
  default: keyof KnownGuards;
21
19
  guards: KnownGuards;
22
20
  }): ConfigProvider<ResolvedAuthConfig<KnownGuards>>;
23
- /**
24
- * Providers helper to configure user providers for
25
- * finding users for authentication
26
- */
27
- export declare const providers: {
28
- db: <RealUser extends Record<string, any>>(config: DatabaseUserProviderOptions<RealUser>) => ConfigProvider<DatabaseUserProvider<RealUser>>;
29
- lucid: <RealUser extends LucidAuthenticatable>(config: LucidUserProviderOptions<RealUser>) => ConfigProvider<LucidUserProvider<RealUser>>;
30
- };
@@ -0,0 +1,105 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import type { HttpContext } from '@adonisjs/core/http';
3
+ /**
4
+ * The "E_UNAUTHORIZED_ACCESS" exception is raised when unable to
5
+ * authenticate an incoming HTTP request.
6
+ *
7
+ * The "error.guardDriverName" can be used to know the driver which
8
+ * raised the error.
9
+ */
10
+ export declare const E_UNAUTHORIZED_ACCESS: {
11
+ new (message: string, options: {
12
+ redirectTo?: string;
13
+ guardDriverName: string;
14
+ }): {
15
+ /**
16
+ * Endpoint to redirect to. Only used by "session" driver
17
+ * renderer
18
+ */
19
+ redirectTo?: string | undefined;
20
+ /**
21
+ * Translation identifier. Can be customized
22
+ */
23
+ identifier: string;
24
+ /**
25
+ * The guard name reference that raised the exception. It allows
26
+ * us to customize the logic of handling the exception.
27
+ */
28
+ guardDriverName: string;
29
+ /**
30
+ * A collection of renderers to render the exception to a
31
+ * response.
32
+ *
33
+ * The collection is a key-value pair, where the key is
34
+ * the guard driver name and value is a factory function
35
+ * to respond to the request.
36
+ */
37
+ renderers: Record<string, (message: string, error: any, ctx: HttpContext) => Promise<void> | void>;
38
+ /**
39
+ * Returns the message to be sent in the HTTP response.
40
+ * Feel free to override this method and return a custom
41
+ * response.
42
+ */
43
+ getResponseMessage(error: any, ctx: HttpContext): string;
44
+ /**
45
+ * Converts exception to an HTTP response
46
+ */
47
+ handle(error: any, ctx: HttpContext): Promise<void>;
48
+ name: string;
49
+ help?: string | undefined;
50
+ code?: string | undefined;
51
+ status: number;
52
+ toString(): string;
53
+ readonly [Symbol.toStringTag]: string;
54
+ message: string;
55
+ stack?: string | undefined;
56
+ cause?: unknown;
57
+ };
58
+ status: number;
59
+ code: string;
60
+ help?: string | undefined;
61
+ message?: string | undefined;
62
+ captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
63
+ prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
64
+ stackTraceLimit: number;
65
+ };
66
+ /**
67
+ * Exception is raised when user credentials are invalid
68
+ */
69
+ export declare const E_INVALID_CREDENTIALS: {
70
+ new (message?: string | undefined, options?: (ErrorOptions & {
71
+ code?: string | undefined;
72
+ status?: number | undefined;
73
+ }) | undefined): {
74
+ /**
75
+ * Translation identifier. Can be customized
76
+ */
77
+ identifier: string;
78
+ /**
79
+ * Returns the message to be sent in the HTTP response.
80
+ * Feel free to override this method and return a custom
81
+ * response.
82
+ */
83
+ getResponseMessage(error: any, ctx: HttpContext): string;
84
+ /**
85
+ * Converts exception to an HTTP response
86
+ */
87
+ handle(error: any, ctx: HttpContext): Promise<void>;
88
+ name: string;
89
+ help?: string | undefined;
90
+ code?: string | undefined;
91
+ status: number;
92
+ toString(): string;
93
+ readonly [Symbol.toStringTag]: string;
94
+ message: string;
95
+ stack?: string | undefined;
96
+ cause?: unknown;
97
+ };
98
+ status: number;
99
+ code: string;
100
+ help?: string | undefined;
101
+ message?: string | undefined;
102
+ captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
103
+ prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
104
+ stackTraceLimit: number;
105
+ };
@@ -1,6 +1,7 @@
1
- import auth from '@adonisjs/auth/services/main';
2
1
  import type { HttpContext } from '@adonisjs/core/http';
3
2
  import type { NextFn } from '@adonisjs/core/types/http';
3
+ import type { Authenticator } from '../authenticator.js';
4
+ import type { Authenticators, GuardFactory } from '../types.js';
4
5
  /**
5
6
  * The "InitializeAuthMiddleware" is used to create a request
6
7
  * specific authenticator instance for every HTTP request.
@@ -13,6 +14,6 @@ export default class InitializeAuthMiddleware {
13
14
  }
14
15
  declare module '@adonisjs/core/http' {
15
16
  interface HttpContext {
16
- auth: ReturnType<(typeof auth)['createAuthenticator']>;
17
+ auth: Authenticator<Authenticators extends Record<string, GuardFactory> ? Authenticators : never>;
17
18
  }
18
19
  }
@@ -0,0 +1,17 @@
1
+ import "../../chunk-CZCFTIBB.js";
2
+
3
+ // src/middleware/initialize_auth_middleware.ts
4
+ var InitializeAuthMiddleware = class {
5
+ async handle(ctx, next) {
6
+ const auth = await ctx.containerResolver.make("auth.manager");
7
+ ctx.auth = auth.createAuthenticator(ctx);
8
+ if ("view" in ctx) {
9
+ ctx.view.share({ auth: ctx.auth });
10
+ }
11
+ return next();
12
+ }
13
+ };
14
+ export {
15
+ InitializeAuthMiddleware as default
16
+ };
17
+ //# sourceMappingURL=initialize_auth_middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/middleware/initialize_auth_middleware.ts"],"sourcesContent":["/// <reference types=\"@adonisjs/core/providers/edge_provider\" />\n\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { NextFn } from '@adonisjs/core/types/http'\n\nimport type { Authenticator } from '../authenticator.js'\nimport type { Authenticators, GuardFactory } from '../types.js'\n\n/**\n * The \"InitializeAuthMiddleware\" is used to create a request\n * specific authenticator instance for every HTTP request.\n *\n * This middleware does not protect routes from unauthenticated\n * users. Please use the \"auth\" middleware for that.\n */\nexport default class InitializeAuthMiddleware {\n async handle(ctx: HttpContext, next: NextFn) {\n const auth = await ctx.containerResolver.make('auth.manager')\n\n /**\n * Initialize the authenticator for the current HTTP\n * request\n */\n ctx.auth = auth.createAuthenticator(ctx)\n\n /**\n * Sharing authenticator with templates\n */\n if ('view' in ctx) {\n ctx.view.share({ auth: ctx.auth })\n }\n\n return next()\n }\n}\n\ndeclare module '@adonisjs/core/http' {\n export interface HttpContext {\n auth: Authenticator<\n Authenticators extends Record<string, GuardFactory> ? Authenticators : never\n >\n }\n}\n"],"mappings":";;;AAeA,IAAqB,2BAArB,MAA8C;AAAA,EAC5C,MAAM,OAAO,KAAkB,MAAc;AAC3C,UAAM,OAAO,MAAM,IAAI,kBAAkB,KAAK,cAAc;AAM5D,QAAI,OAAO,KAAK,oBAAoB,GAAG;AAKvC,QAAI,UAAU,KAAK;AACjB,UAAI,KAAK,MAAM,EAAE,MAAM,IAAI,KAAK,CAAC;AAAA,IACnC;AAEA,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
@@ -0,0 +1,156 @@
1
+ import type { Hash } from '@adonisjs/core/hash';
2
+ import type { NormalizeConstructor } from '@adonisjs/core/types/helpers';
3
+ /**
4
+ * Mixing to add user lookup and password verification methods
5
+ * on a model.
6
+ *
7
+ * Under the hood, this mixin defines following methods and hooks
8
+ *
9
+ * - beforeSave hook to hash user password
10
+ * - findForAuth method to find a user during authentication
11
+ * - verifyCredentials method to verify user credentials and prevent
12
+ * timing attacks.
13
+ */
14
+ export declare function withAuthFinder(hash: Hash, options: {
15
+ uids: string[];
16
+ passwordColumnName: string;
17
+ }): <Model extends NormalizeConstructor<import("@adonisjs/lucid/types/model").LucidModel>>(superclass: Model) => {
18
+ new (...args: any[]): {
19
+ $attributes: import("@adonisjs/lucid/types/model").ModelObject;
20
+ $extras: import("@adonisjs/lucid/types/model").ModelObject;
21
+ $original: import("@adonisjs/lucid/types/model").ModelObject;
22
+ $preloaded: {
23
+ [relation: string]: import("@adonisjs/lucid/types/model").LucidRow | import("@adonisjs/lucid/types/model").LucidRow[];
24
+ };
25
+ $columns: undefined;
26
+ $sideloaded: import("@adonisjs/lucid/types/model").ModelObject;
27
+ $primaryKeyValue?: string | number | undefined;
28
+ $isPersisted: boolean;
29
+ $isNew: boolean;
30
+ $isLocal: boolean;
31
+ $dirty: import("@adonisjs/lucid/types/model").ModelObject;
32
+ $isDirty: boolean;
33
+ $isDeleted: boolean;
34
+ $options?: import("@adonisjs/lucid/types/model").ModelOptions | undefined;
35
+ $trx?: import("@adonisjs/lucid/types/database").TransactionClientContract | undefined;
36
+ $setOptionsAndTrx(options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions | undefined): void;
37
+ useTransaction(trx: import("@adonisjs/lucid/types/database").TransactionClientContract): any;
38
+ useConnection(connection: string): any;
39
+ $getQueryFor(action: "insert", client: import("@adonisjs/lucid/types/database").QueryClientContract): import("@adonisjs/lucid/types/querybuilder").InsertQueryBuilderContract<unknown[]>;
40
+ $getQueryFor(action: "delete" | "refresh" | "update", client: import("@adonisjs/lucid/types/database").QueryClientContract): import("@adonisjs/lucid/types/model").ModelQueryBuilderContract<import("@adonisjs/lucid/types/model").LucidModel, import("@adonisjs/lucid/types/model").LucidRow>;
41
+ $setAttribute(key: string, value: any): void;
42
+ $getAttribute(key: string): any;
43
+ $getAttributeFromCache(key: string, callback: (value: any) => any): any;
44
+ $hasRelated(key: string): boolean;
45
+ $setRelated(key: string, result: import("@adonisjs/lucid/types/querybuilder").OneOrMany<import("@adonisjs/lucid/types/model").LucidRow> | null): void;
46
+ $pushRelated(key: string, result: import("@adonisjs/lucid/types/querybuilder").OneOrMany<import("@adonisjs/lucid/types/model").LucidRow> | null): void;
47
+ $getRelated(key: string, defaultValue?: any): import("@adonisjs/lucid/types/querybuilder").OneOrMany<import("@adonisjs/lucid/types/model").LucidRow> | null | undefined;
48
+ $consumeAdapterResult(adapterResult: import("@adonisjs/lucid/types/model").ModelObject, sideloadAttributes?: import("@adonisjs/lucid/types/model").ModelObject | undefined): void;
49
+ $hydrateOriginals(): void;
50
+ fill(value: Partial<{}>, allowExtraProperties?: boolean | undefined): any;
51
+ merge(value: Partial<{}>, allowExtraProperties?: boolean | undefined): any;
52
+ enableForceUpdate(): any;
53
+ save(): Promise<any>;
54
+ delete(): Promise<void>;
55
+ refresh(): Promise<any>;
56
+ load: import("@adonisjs/lucid/types/model").LucidRowPreload<any>;
57
+ preload: import("@adonisjs/lucid/types/model").LucidRowPreload<any>;
58
+ loadAggregate: <Self extends any, Name extends import("@adonisjs/lucid/types/relations").ExtractModelRelations<Self>, RelatedBuilder = Self[Name] extends import("@adonisjs/lucid/types/relations").ModelRelations<import("@adonisjs/lucid/types/model").LucidModel, import("@adonisjs/lucid/types/model").LucidModel> ? Self[Name]["subQuery"] : never>(name: Name, callback: (builder: RelatedBuilder) => void) => import("@adonisjs/lucid/types/model").LazyLoadAggregatesContract<Self>;
59
+ loadCount: <Self_1 extends any, Name_1 extends import("@adonisjs/lucid/types/relations").ExtractModelRelations<Self_1>, RelatedBuilder_1 = Self_1[Name_1] extends import("@adonisjs/lucid/types/relations").ModelRelations<import("@adonisjs/lucid/types/model").LucidModel, import("@adonisjs/lucid/types/model").LucidModel> ? Self_1[Name_1]["subQuery"] : never>(name: Name_1, callback?: ((builder: RelatedBuilder_1) => void) | undefined) => import("@adonisjs/lucid/types/model").LazyLoadAggregatesContract<Self_1>;
60
+ serializeAttributes(fields?: import("@adonisjs/lucid/types/model").CherryPickFields | undefined, raw?: boolean | undefined): import("@adonisjs/lucid/types/model").ModelObject;
61
+ serializeComputed(fields?: import("@adonisjs/lucid/types/model").CherryPickFields | undefined): import("@adonisjs/lucid/types/model").ModelObject;
62
+ serializeRelations(fields: undefined, raw: true): {
63
+ [key: string]: import("@adonisjs/lucid/types/model").LucidRow | import("@adonisjs/lucid/types/model").LucidRow[];
64
+ };
65
+ serializeRelations(cherryPick: {
66
+ [relation: string]: import("@adonisjs/lucid/types/model").CherryPick;
67
+ } | undefined, raw: false | undefined): import("@adonisjs/lucid/types/model").ModelObject;
68
+ serializeRelations(cherryPick?: {
69
+ [relation: string]: import("@adonisjs/lucid/types/model").CherryPick;
70
+ } | undefined, raw?: boolean | undefined): import("@adonisjs/lucid/types/model").ModelObject;
71
+ serialize(cherryPick?: import("@adonisjs/lucid/types/model").CherryPick | undefined): import("@adonisjs/lucid/types/model").ModelObject;
72
+ toObject(): import("@adonisjs/lucid/types/model").ModelObject;
73
+ toJSON(): import("@adonisjs/lucid/types/model").ModelObject;
74
+ related<Name_2 extends undefined>(relation: Name_2): any[Name_2] extends import("@adonisjs/lucid/types/relations").ModelRelations<import("@adonisjs/lucid/types/model").LucidModel, import("@adonisjs/lucid/types/model").LucidModel> ? any[Name_2]["client"] : never;
75
+ };
76
+ /**
77
+ * Hook to verify user password when creating or updating
78
+ * the user model.
79
+ */
80
+ hashPassword<T extends any & Model>(this: T, user: InstanceType<T>): Promise<void>;
81
+ /**
82
+ * Finds the user for authentication via "verifyCredentials".
83
+ * Feel free to override this method customize the user
84
+ * lookup behavior.
85
+ */
86
+ findForAuth<T_1 extends any & Model>(this: T_1, uids: string[], value: string): Promise<InstanceType<T_1> | null>;
87
+ /**
88
+ * Find a user by uid and verify their password. This method is
89
+ * safe from timing attacks.
90
+ */
91
+ verifyCredentials<T_2 extends any & Model>(this: T_2, uid: string, password: string): Promise<InstanceType<T_2>>;
92
+ readonly booted: boolean;
93
+ find: <T_3 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_3, value: any, options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions | undefined) => Promise<InstanceType<T_3> | null>;
94
+ $columnsDefinitions: Map<string, import("@adonisjs/lucid/types/model").ModelColumnOptions>;
95
+ $relationsDefinitions: Map<string, import("@adonisjs/lucid/types/relations").RelationshipsContract>;
96
+ $computedDefinitions: Map<string, import("@adonisjs/lucid/types/model").ComputedOptions>;
97
+ primaryKey: string;
98
+ connection?: string | undefined;
99
+ namingStrategy: import("@adonisjs/lucid/types/model").NamingStrategyContract;
100
+ table: string;
101
+ selfAssignPrimaryKey: boolean;
102
+ $adapter: import("@adonisjs/lucid/types/model").AdapterContract;
103
+ useAdapter: (adapter: import("@adonisjs/lucid/types/model").AdapterContract) => void;
104
+ $hooks: import("@poppinss/hooks").default<any>;
105
+ $keys: {
106
+ attributesToColumns: import("@adonisjs/lucid/types/model").ModelKeysContract;
107
+ attributesToSerialized: import("@adonisjs/lucid/types/model").ModelKeysContract;
108
+ columnsToAttributes: import("@adonisjs/lucid/types/model").ModelKeysContract;
109
+ columnsToSerialized: import("@adonisjs/lucid/types/model").ModelKeysContract;
110
+ serializedToColumns: import("@adonisjs/lucid/types/model").ModelKeysContract;
111
+ serializedToAttributes: import("@adonisjs/lucid/types/model").ModelKeysContract;
112
+ };
113
+ $createFromAdapterResult: <T_4 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_4, result?: import("@adonisjs/lucid/types/model").ModelObject | undefined, sideloadAttributes?: import("@adonisjs/lucid/types/model").ModelObject | undefined, options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions | undefined) => InstanceType<T_4> | null;
114
+ $createMultipleFromAdapterResult: <T_5 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_5, results: import("@adonisjs/lucid/types/model").ModelObject[], sideloadAttributes?: import("@adonisjs/lucid/types/model").ModelObject | undefined, options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions | undefined) => InstanceType<T_5>[];
115
+ $addColumn: (name: string, options: Partial<import("@adonisjs/lucid/types/model").ColumnOptions>) => import("@adonisjs/lucid/types/model").ColumnOptions;
116
+ $hasColumn: (name: string) => boolean;
117
+ $getColumn: (name: string) => import("@adonisjs/lucid/types/model").ModelColumnOptions | undefined;
118
+ $addComputed: (name: string, options: Partial<import("@adonisjs/lucid/types/model").ComputedOptions>) => import("@adonisjs/lucid/types/model").ComputedOptions;
119
+ $hasComputed: (name: string) => boolean;
120
+ $getComputed: (name: string) => import("@adonisjs/lucid/types/model").ComputedOptions | undefined;
121
+ $addRelation: (name: string, type: "hasOne" | "hasMany" | "belongsTo" | "manyToMany" | "hasManyThrough", relatedModel: () => import("@adonisjs/lucid/types/model").LucidModel, options: import("@adonisjs/lucid/types/model").ModelRelationOptions) => void;
122
+ $hasRelation: (name: string) => boolean;
123
+ $getRelation: {
124
+ <Model_1 extends import("@adonisjs/lucid/types/model").LucidModel, Name_3 extends import("@adonisjs/lucid/types/relations").ExtractModelRelations<InstanceType<Model_1>>>(this: Model_1, name: Name_3): InstanceType<Model_1>[Name_3] extends import("@adonisjs/lucid/types/relations").ModelRelations<import("@adonisjs/lucid/types/model").LucidModel, import("@adonisjs/lucid/types/model").LucidModel> ? InstanceType<Model_1>[Name_3]["client"]["relation"] : import("@adonisjs/lucid/types/relations").RelationshipsContract;
125
+ <Model_2 extends import("@adonisjs/lucid/types/model").LucidModel>(this: Model_2, name: string): import("@adonisjs/lucid/types/relations").RelationshipsContract;
126
+ };
127
+ $defineProperty: <Model_3 extends import("@adonisjs/lucid/types/model").LucidModel, Prop extends keyof Model_3>(this: Model_3, propertyName: Prop, defaultValue: Model_3[Prop], strategy: "inherit" | "define" | ((value: Model_3[Prop]) => Model_3[Prop])) => void;
128
+ boot: () => void;
129
+ before: {
130
+ <Model_4 extends import("@adonisjs/lucid/types/model").LucidModel, Event_1 extends "find" | "fetch">(this: Model_4, event: Event_1, handler: import("@adonisjs/lucid/types/model").HooksHandler<import("@adonisjs/lucid/types/model").ModelQueryBuilderContract<Model_4, InstanceType<Model_4>>, Event_1>): void;
131
+ <Model_5 extends import("@adonisjs/lucid/types/model").LucidModel>(this: Model_5, event: "paginate", handler: import("@adonisjs/lucid/types/model").HooksHandler<[import("@adonisjs/lucid/types/model").ModelQueryBuilderContract<Model_5, InstanceType<Model_5>>, import("@adonisjs/lucid/types/model").ModelQueryBuilderContract<Model_5, InstanceType<Model_5>>], "paginate">): void;
132
+ <Model_6 extends import("@adonisjs/lucid/types/model").LucidModel, Event_2 extends import("@adonisjs/lucid/types/model").EventsList>(this: Model_6, event: Event_2, handler: import("@adonisjs/lucid/types/model").HooksHandler<InstanceType<Model_6>, Event_2>): void;
133
+ };
134
+ after: {
135
+ <Model_7 extends import("@adonisjs/lucid/types/model").LucidModel>(this: Model_7, event: "fetch", handler: import("@adonisjs/lucid/types/model").HooksHandler<InstanceType<Model_7>[], "fetch">): void;
136
+ <Model_8 extends import("@adonisjs/lucid/types/model").LucidModel>(this: Model_8, event: "paginate", handler: import("@adonisjs/lucid/types/model").HooksHandler<import("@adonisjs/lucid/types/model").ModelPaginatorContract<InstanceType<Model_8>>, "paginate">): void;
137
+ <Model_9 extends import("@adonisjs/lucid/types/model").LucidModel, Event_3 extends import("@adonisjs/lucid/types/model").EventsList>(this: Model_9, event: Event_3, handler: import("@adonisjs/lucid/types/model").HooksHandler<InstanceType<Model_9>, Event_3>): void;
138
+ };
139
+ create: <T_6 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_6, values: Partial<import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_6>>>, options?: import("@adonisjs/lucid/types/model").ModelAssignOptions | undefined) => Promise<InstanceType<T_6>>;
140
+ createMany: <T_7 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_7, values: Partial<import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_7>>>[], options?: import("@adonisjs/lucid/types/model").ModelAssignOptions | undefined) => Promise<InstanceType<T_7>[]>;
141
+ findOrFail: <T_8 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_8, value: any, options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions | undefined) => Promise<InstanceType<T_8>>;
142
+ findBy: <T_9 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_9, key: string, value: any, options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions | undefined) => Promise<InstanceType<T_9> | null>;
143
+ findByOrFail: <T_10 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_10, key: string, value: any, options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions | undefined) => Promise<InstanceType<T_10>>;
144
+ first: <T_11 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_11, options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions | undefined) => Promise<InstanceType<T_11> | null>;
145
+ firstOrFail: <T_12 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_12, options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions | undefined) => Promise<InstanceType<T_12>>;
146
+ findMany: <T_13 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_13, value: any[], options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions | undefined) => Promise<InstanceType<T_13>[]>;
147
+ firstOrNew: <T_14 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_14, searchPayload: Partial<import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_14>>>, savePayload?: Partial<import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_14>>> | undefined, options?: import("@adonisjs/lucid/types/model").ModelAssignOptions | undefined) => Promise<InstanceType<T_14>>;
148
+ firstOrCreate: <T_15 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_15, searchPayload: Partial<import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_15>>>, savePayload?: Partial<import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_15>>> | undefined, options?: import("@adonisjs/lucid/types/model").ModelAssignOptions | undefined) => Promise<InstanceType<T_15>>;
149
+ updateOrCreate: <T_16 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_16, searchPayload: Partial<import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_16>>>, updatePayload: Partial<import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_16>>>, options?: import("@adonisjs/lucid/types/model").ModelAssignOptions | undefined) => Promise<InstanceType<T_16>>;
150
+ fetchOrNewUpMany: <T_17 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_17, predicate: keyof import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_17>> | (keyof import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_17>>)[], payload: Partial<import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_17>>>[], options?: import("@adonisjs/lucid/types/model").ModelAssignOptions | undefined) => Promise<InstanceType<T_17>[]>;
151
+ fetchOrCreateMany: <T_18 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_18, predicate: keyof import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_18>> | (keyof import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_18>>)[], payload: Partial<import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_18>>>[], options?: import("@adonisjs/lucid/types/model").ModelAssignOptions | undefined) => Promise<InstanceType<T_18>[]>;
152
+ updateOrCreateMany: <T_19 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_19, predicate: keyof import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_19>> | (keyof import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_19>>)[], payload: Partial<import("@adonisjs/lucid/types/model").ModelAttributes<InstanceType<T_19>>>[], options?: import("@adonisjs/lucid/types/model").ModelAssignOptions | undefined) => Promise<InstanceType<T_19>[]>;
153
+ all: <T_20 extends import("@adonisjs/lucid/types/model").LucidModel>(this: T_20, options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions | undefined) => Promise<InstanceType<T_20>[]>;
154
+ query: <Model_10 extends import("@adonisjs/lucid/types/model").LucidModel, Result = InstanceType<Model_10>>(this: Model_10, options?: import("@adonisjs/lucid/types/model").ModelAdapterOptions | undefined) => import("@adonisjs/lucid/types/model").ModelQueryBuilderContract<Model_10, Result>;
155
+ truncate: (cascade?: boolean | undefined) => Promise<void>;
156
+ } & Model;
@@ -4,16 +4,16 @@ import type { Authenticators, GuardContract, GuardFactory } from '../../types.js
4
4
  declare module '@japa/api-client' {
5
5
  interface ApiRequest {
6
6
  authData: {
7
- guard: string;
8
- user: unknown;
7
+ guard: keyof Authenticators | '__default__';
8
+ args: [unknown, ...any[]];
9
9
  };
10
10
  /**
11
- * Login a user using the default authentication
12
- * guard when making an API call
11
+ * Login a user using the default authentication guard
12
+ * when making an API call
13
13
  */
14
- loginAs(user: {
15
- [K in keyof Authenticators]: Authenticators[K] extends GuardFactory ? ReturnType<Authenticators[K]> extends GuardContract<infer A> ? A : never : never;
16
- }): this;
14
+ loginAs(...args: {
15
+ [K in keyof Authenticators]: Authenticators[K] extends GuardFactory ? ReturnType<Authenticators[K]> extends GuardContract<unknown> ? Parameters<ReturnType<Authenticators[K]>['authenticateAsClient']> : never : never;
16
+ }[keyof Authenticators]): this;
17
17
  /**
18
18
  * Define the authentication guard for login
19
19
  */
@@ -21,7 +21,7 @@ declare module '@japa/api-client' {
21
21
  /**
22
22
  * Login a user using a specific auth guard
23
23
  */
24
- loginAs(user: Authenticators[K] extends GuardFactory ? ReturnType<Authenticators[K]> extends GuardContract<infer A> ? A : never : never): Self;
24
+ loginAs(...args: ReturnType<Authenticators[K]> extends GuardContract<any> ? Parameters<ReturnType<Authenticators[K]>['authenticateAsClient']> : never): Self;
25
25
  };
26
26
  }
27
27
  }
@@ -0,0 +1,59 @@
1
+ import {
2
+ debug_default
3
+ } from "../../../chunk-3HZHOWKL.js";
4
+ import "../../../chunk-CZCFTIBB.js";
5
+
6
+ // src/plugins/japa/api_client.ts
7
+ import { ApiClient, ApiRequest } from "@japa/api-client";
8
+ var authApiClient = (app) => {
9
+ const pluginFn = function() {
10
+ debug_default("installing auth api client plugin");
11
+ ApiRequest.macro("loginAs", function(user, ...args) {
12
+ this.authData = {
13
+ guard: "__default__",
14
+ args: [user, ...args]
15
+ };
16
+ return this;
17
+ });
18
+ ApiRequest.macro("withGuard", function(guard) {
19
+ return {
20
+ loginAs: (...args) => {
21
+ this.authData = {
22
+ guard,
23
+ args
24
+ };
25
+ return this;
26
+ }
27
+ };
28
+ });
29
+ ApiClient.setup(async (request) => {
30
+ const auth = await app.container.make("auth.manager");
31
+ const authData = request["authData"];
32
+ if (!authData) {
33
+ return;
34
+ }
35
+ const client = auth.createAuthenticatorClient();
36
+ const guard = authData.guard === "__default__" ? client.use() : client.use(authData.guard);
37
+ const requestData = await guard.authenticateAsClient(
38
+ ...authData.args
39
+ );
40
+ if (requestData.headers) {
41
+ debug_default("defining headers with api client request %O", requestData.headers);
42
+ request.headers(requestData.headers);
43
+ }
44
+ if (requestData.session) {
45
+ debug_default("defining session with api client request %O", requestData.session);
46
+ request.withSession(requestData.session);
47
+ }
48
+ if (requestData.cookies) {
49
+ debug_default("defining session with api client request %O", requestData.session);
50
+ request.cookies(requestData.cookies);
51
+ }
52
+ });
53
+ };
54
+ return pluginFn;
55
+ };
56
+ export {
57
+ authApiClient
58
+ };
59
+ //# sourceMappingURL=api_client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/plugins/japa/api_client.ts"],"sourcesContent":["/*\n * @adonisjs/auth\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\n/// <reference types=\"@adonisjs/session/plugins/api_client\" />\n\nimport type { PluginFn } from '@japa/runner/types'\nimport { ApiClient, ApiRequest } from '@japa/api-client'\nimport type { ApplicationService } from '@adonisjs/core/types'\n\nimport debug from '../../debug.js'\nimport type { Authenticators, GuardContract, GuardFactory } from '../../types.js'\n\ndeclare module '@japa/api-client' {\n export interface ApiRequest {\n authData: {\n guard: keyof Authenticators | '__default__'\n args: [unknown, ...any[]]\n }\n\n /**\n * Login a user using the default authentication guard\n * when making an API call\n */\n loginAs(\n ...args: {\n [K in keyof Authenticators]: Authenticators[K] extends GuardFactory\n ? ReturnType<Authenticators[K]> extends GuardContract<unknown>\n ? Parameters<ReturnType<Authenticators[K]>['authenticateAsClient']>\n : never\n : never\n }[keyof Authenticators]\n ): this\n\n /**\n * Define the authentication guard for login\n */\n withGuard<K extends keyof Authenticators, Self extends ApiRequest>(\n this: Self,\n guard: K\n ): {\n /**\n * Login a user using a specific auth guard\n */\n loginAs(\n ...args: ReturnType<Authenticators[K]> extends GuardContract<any>\n ? Parameters<ReturnType<Authenticators[K]>['authenticateAsClient']>\n : never\n ): Self\n }\n }\n}\n\n/**\n * Auth API client to authenticate users when making\n * HTTP requests using the Japa API client\n */\nexport const authApiClient = (app: ApplicationService) => {\n const pluginFn: PluginFn = function () {\n debug('installing auth api client plugin')\n\n /**\n * Login a user using the default authentication guard\n * when making an API call\n */\n ApiRequest.macro('loginAs', function (this: ApiRequest, user, ...args: any[]) {\n this.authData = {\n guard: '__default__',\n args: [user, ...args],\n }\n return this\n })\n\n /**\n * Define the authentication guard for login\n */\n ApiRequest.macro('withGuard', function <\n K extends keyof Authenticators,\n Self extends ApiRequest,\n >(this: Self, guard: K) {\n return {\n loginAs: (...args) => {\n this.authData = {\n guard,\n args: args,\n }\n return this\n },\n }\n })\n\n /**\n * Hook into the request and login the user\n */\n ApiClient.setup(async (request) => {\n const auth = await app.container.make('auth.manager')\n const authData = request['authData']\n if (!authData) {\n return\n }\n\n const client = auth.createAuthenticatorClient()\n const guard = authData.guard === '__default__' ? client.use() : client.use(authData.guard)\n const requestData = await (guard as GuardContract<unknown>).authenticateAsClient(\n ...authData.args\n )\n\n /* c8 ignore next 13 */\n if (requestData.headers) {\n debug('defining headers with api client request %O', requestData.headers)\n request.headers(requestData.headers)\n }\n if (requestData.session) {\n debug('defining session with api client request %O', requestData.session)\n request.withSession(requestData.session)\n }\n if (requestData.cookies) {\n debug('defining session with api client request %O', requestData.session)\n request.cookies(requestData.cookies)\n }\n })\n }\n\n return pluginFn\n}\n"],"mappings":";;;;;;AAYA,SAAS,WAAW,kBAAkB;AAkD/B,IAAM,gBAAgB,CAAC,QAA4B;AACxD,QAAM,WAAqB,WAAY;AACrC,kBAAM,mCAAmC;AAMzC,eAAW,MAAM,WAAW,SAA4B,SAAS,MAAa;AAC5E,WAAK,WAAW;AAAA,QACd,OAAO;AAAA,QACP,MAAM,CAAC,MAAM,GAAG,IAAI;AAAA,MACtB;AACA,aAAO;AAAA,IACT,CAAC;AAKD,eAAW,MAAM,aAAa,SAGhB,OAAU;AACtB,aAAO;AAAA,QACL,SAAS,IAAI,SAAS;AACpB,eAAK,WAAW;AAAA,YACd;AAAA,YACA;AAAA,UACF;AACA,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,IACF,CAAC;AAKD,cAAU,MAAM,OAAO,YAAY;AACjC,YAAM,OAAO,MAAM,IAAI,UAAU,KAAK,cAAc;AACpD,YAAM,WAAW,QAAQ,UAAU;AACnC,UAAI,CAAC,UAAU;AACb;AAAA,MACF;AAEA,YAAM,SAAS,KAAK,0BAA0B;AAC9C,YAAM,QAAQ,SAAS,UAAU,gBAAgB,OAAO,IAAI,IAAI,OAAO,IAAI,SAAS,KAAK;AACzF,YAAM,cAAc,MAAO,MAAiC;AAAA,QAC1D,GAAG,SAAS;AAAA,MACd;AAGA,UAAI,YAAY,SAAS;AACvB,sBAAM,+CAA+C,YAAY,OAAO;AACxE,gBAAQ,QAAQ,YAAY,OAAO;AAAA,MACrC;AACA,UAAI,YAAY,SAAS;AACvB,sBAAM,+CAA+C,YAAY,OAAO;AACxE,gBAAQ,YAAY,YAAY,OAAO;AAAA,MACzC;AACA,UAAI,YAAY,SAAS;AACvB,sBAAM,+CAA+C,YAAY,OAAO;AACxE,gBAAQ,QAAQ,YAAY,OAAO;AAAA,MACrC;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;","names":[]}
@@ -4,13 +4,12 @@ import type { Authenticators, GuardContract, GuardFactory } from '../../types.js
4
4
  declare module 'playwright' {
5
5
  interface BrowserContext {
6
6
  /**
7
- * Login a user using the default authentication
8
- * guard when using the browser context to
9
- * make page visits
7
+ * Login a user using the default authentication guard when
8
+ * using the browser context to make page visits
10
9
  */
11
- loginAs(user: {
12
- [K in keyof Authenticators]: Authenticators[K] extends GuardFactory ? ReturnType<Authenticators[K]> extends GuardContract<infer A> ? A : never : never;
13
- }): Promise<void>;
10
+ loginAs(...args: {
11
+ [K in keyof Authenticators]: Authenticators[K] extends GuardFactory ? ReturnType<Authenticators[K]> extends GuardContract<unknown> ? Parameters<ReturnType<Authenticators[K]>['authenticateAsClient']> : never : never;
12
+ }[keyof Authenticators]): Promise<void>;
14
13
  /**
15
14
  * Define the authentication guard for login
16
15
  */
@@ -18,8 +17,12 @@ declare module 'playwright' {
18
17
  /**
19
18
  * Login a user using a specific auth guard
20
19
  */
21
- loginAs(user: Authenticators[K] extends GuardFactory ? ReturnType<Authenticators[K]> extends GuardContract<infer A> ? A : never : never): Promise<void>;
20
+ loginAs(...args: ReturnType<Authenticators[K]> extends GuardContract<unknown> ? Parameters<ReturnType<Authenticators[K]>['authenticateAsClient']> : never): Promise<void>;
22
21
  };
23
22
  }
24
23
  }
24
+ /**
25
+ * Browser API client to authenticate users when making
26
+ * HTTP requests using the Japa Browser client.
27
+ */
25
28
  export declare const authBrowserClient: (app: ApplicationService) => PluginFn;