@adonisjs/auth 9.5.0 → 10.0.0-next.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 (43) hide show
  1. package/build/{chunk-SAW2RPCA.js → chunk-MSPAYMZE.js} +94 -4
  2. package/build/{chunk-MUPAP5IP.js → chunk-S5G5RTJX.js} +40 -0
  3. package/build/index.d.ts +8 -8
  4. package/build/index.js +2 -2
  5. package/build/modules/access_tokens_guard/access_token.d.ts +103 -0
  6. package/build/modules/access_tokens_guard/crc32.d.ts +39 -0
  7. package/build/modules/access_tokens_guard/define_config.d.ts +4 -4
  8. package/build/modules/access_tokens_guard/guard.d.ts +82 -5
  9. package/build/modules/access_tokens_guard/main.d.ts +5 -5
  10. package/build/modules/access_tokens_guard/main.js +339 -4
  11. package/build/modules/access_tokens_guard/token_providers/db.d.ts +102 -4
  12. package/build/modules/access_tokens_guard/types.d.ts +2 -2
  13. package/build/modules/access_tokens_guard/user_providers/lucid.d.ts +77 -4
  14. package/build/modules/basic_auth_guard/define_config.d.ts +4 -4
  15. package/build/modules/basic_auth_guard/guard.d.ts +16 -3
  16. package/build/modules/basic_auth_guard/main.d.ts +3 -3
  17. package/build/modules/basic_auth_guard/main.js +11 -1
  18. package/build/modules/basic_auth_guard/types.d.ts +1 -1
  19. package/build/modules/basic_auth_guard/user_providers/lucid.d.ts +19 -2
  20. package/build/modules/session_guard/define_config.d.ts +4 -4
  21. package/build/modules/session_guard/guard.d.ts +42 -3
  22. package/build/modules/session_guard/main.d.ts +5 -5
  23. package/build/modules/session_guard/main.js +349 -124
  24. package/build/modules/session_guard/remember_me_token.d.ts +64 -0
  25. package/build/modules/session_guard/token_providers/db.d.ts +92 -2
  26. package/build/modules/session_guard/types.d.ts +2 -2
  27. package/build/modules/session_guard/user_providers/lucid.d.ts +78 -5
  28. package/build/providers/auth_provider.d.ts +22 -1
  29. package/build/providers/auth_provider.js +16 -3
  30. package/build/services/auth.d.ts +1 -1
  31. package/build/src/auth_manager.d.ts +25 -4
  32. package/build/src/authenticator.d.ts +55 -3
  33. package/build/src/authenticator_client.d.ts +18 -1
  34. package/build/src/define_config.d.ts +19 -1
  35. package/build/src/errors.d.ts +31 -0
  36. package/build/src/middleware/initialize_auth_middleware.d.ts +15 -2
  37. package/build/src/middleware/initialize_auth_middleware.js +10 -0
  38. package/build/src/mixins/lucid.d.ts +13 -0
  39. package/build/src/mixins/lucid.js +27 -2
  40. package/build/src/plugins/japa/api_client.d.ts +10 -1
  41. package/build/src/plugins/japa/browser_client.d.ts +10 -1
  42. package/build/src/types.d.ts +141 -29
  43. package/package.json +23 -22
@@ -1,18 +1,37 @@
1
1
  import type { Secret } from '@adonisjs/core/helpers';
2
2
  import type { LucidModel } from '@adonisjs/lucid/types/model';
3
- import { AccessToken } from '../access_token.js';
4
- import type { AccessTokenDbColumns, AccessTokensProviderContract, DbAccessTokensProviderOptions } from '../types.js';
3
+ import { AccessToken } from '../access_token.ts';
4
+ import type { AccessTokenDbColumns, AccessTokensProviderContract, DbAccessTokensProviderOptions } from '../types.ts';
5
5
  /**
6
6
  * DbAccessTokensProvider uses lucid database service to fetch and
7
7
  * persist tokens for a given user.
8
8
  *
9
9
  * The user must be an instance of the associated user model.
10
+ *
11
+ * @template TokenableModel - The Lucid model that can have tokens
12
+ *
13
+ * @example
14
+ * const provider = new DbAccessTokensProvider({
15
+ * tokenableModel: () => import('#models/user'),
16
+ * table: 'api_tokens',
17
+ * type: 'api_token',
18
+ * prefix: 'api_'
19
+ * })
10
20
  */
11
21
  export declare class DbAccessTokensProvider<TokenableModel extends LucidModel> implements AccessTokensProviderContract<TokenableModel> {
12
22
  #private;
13
23
  protected options: DbAccessTokensProviderOptions<TokenableModel>;
14
24
  /**
15
25
  * Create tokens provider instance for a given Lucid model
26
+ *
27
+ * @param model - The tokenable model factory function
28
+ * @param options - Optional configuration options
29
+ *
30
+ * @example
31
+ * const provider = DbAccessTokensProvider.forModel(
32
+ * () => import('#models/user'),
33
+ * { prefix: 'api_', type: 'api_token' }
34
+ * )
16
35
  */
17
36
  static forModel<TokenableModel extends LucidModel>(model: DbAccessTokensProviderOptions<TokenableModel>['tokenableModel'], options?: Omit<DbAccessTokensProviderOptions<TokenableModel>, 'tokenableModel'>): DbAccessTokensProvider<TokenableModel>;
18
37
  /**
@@ -37,17 +56,57 @@ export declare class DbAccessTokensProvider<TokenableModel extends LucidModel> i
37
56
  * secure random string.
38
57
  */
39
58
  protected tokenSecretLength: number;
59
+ /**
60
+ * Creates a new DbAccessTokensProvider instance
61
+ *
62
+ * @param options - Configuration options for the provider
63
+ *
64
+ * @example
65
+ * const provider = new DbAccessTokensProvider({
66
+ * tokenableModel: () => import('#models/user'),
67
+ * table: 'auth_access_tokens',
68
+ * tokenSecretLength: 40,
69
+ * type: 'auth_token',
70
+ * prefix: 'oat_'
71
+ * })
72
+ */
40
73
  constructor(options: DbAccessTokensProviderOptions<TokenableModel>);
41
74
  /**
42
- * Maps a database row to an instance token instance
75
+ * Maps a database row to an AccessToken instance
76
+ *
77
+ * @param dbRow - The database row containing token data
78
+ *
79
+ * @example
80
+ * const token = provider.dbRowToAccessToken({
81
+ * id: 1,
82
+ * tokenable_id: 123,
83
+ * type: 'auth_token',
84
+ * hash: 'sha256hash',
85
+ * // ... other columns
86
+ * })
43
87
  */
44
88
  protected dbRowToAccessToken(dbRow: AccessTokenDbColumns): AccessToken;
45
89
  /**
46
90
  * Returns a query client instance from the parent model
91
+ *
92
+ * @example
93
+ * const db = await provider.getDb()
94
+ * const tokens = await db.from('auth_access_tokens').select('*')
47
95
  */
48
96
  protected getDb(): Promise<import("@adonisjs/lucid/types/database").QueryClientContract>;
49
97
  /**
50
98
  * Create a token for a user
99
+ *
100
+ * @param user - The user instance to create a token for
101
+ * @param abilities - Array of abilities the token should have
102
+ * @param options - Optional token configuration
103
+ *
104
+ * @example
105
+ * const token = await provider.create(user, ['read', 'write'], {
106
+ * name: 'Mobile App Token',
107
+ * expiresIn: '7d'
108
+ * })
109
+ * console.log('Token:', token.value.release())
51
110
  */
52
111
  create(user: InstanceType<TokenableModel>, abilities?: string[], options?: {
53
112
  name?: string;
@@ -55,14 +114,37 @@ export declare class DbAccessTokensProvider<TokenableModel extends LucidModel> i
55
114
  }): Promise<AccessToken>;
56
115
  /**
57
116
  * Find a token for a user by the token id
117
+ *
118
+ * @param user - The user instance that owns the token
119
+ * @param identifier - The token identifier to search for
120
+ *
121
+ * @example
122
+ * const token = await provider.find(user, 123)
123
+ * if (token) {
124
+ * console.log('Found token:', token.name)
125
+ * }
58
126
  */
59
127
  find(user: InstanceType<TokenableModel>, identifier: string | number | BigInt): Promise<AccessToken | null>;
60
128
  /**
61
129
  * Delete a token by its id
130
+ *
131
+ * @param user - The user instance that owns the token
132
+ * @param identifier - The token identifier to delete
133
+ *
134
+ * @example
135
+ * const deletedCount = await provider.delete(user, 123)
136
+ * console.log('Deleted tokens:', deletedCount)
62
137
  */
63
138
  delete(user: InstanceType<TokenableModel>, identifier: string | number | BigInt): Promise<number>;
64
139
  /**
65
- * Returns all the tokens a given user
140
+ * Returns all the tokens for a given user
141
+ *
142
+ * @param user - The user instance to get tokens for
143
+ *
144
+ * @example
145
+ * const tokens = await provider.all(user)
146
+ * console.log('User has', tokens.length, 'tokens')
147
+ * tokens.forEach(token => console.log(token.name))
66
148
  */
67
149
  all(user: InstanceType<TokenableModel>): Promise<AccessToken[]>;
68
150
  /**
@@ -71,10 +153,26 @@ export declare class DbAccessTokensProvider<TokenableModel extends LucidModel> i
71
153
  *
72
154
  * Returns null when unable to verify the token or find it
73
155
  * inside the storage
156
+ *
157
+ * @param tokenValue - The token value to verify
158
+ *
159
+ * @example
160
+ * const token = await provider.verify(new Secret('oat_abc123.def456'))
161
+ * if (token && !token.isExpired()) {
162
+ * console.log('Valid token for user:', token.tokenableId)
163
+ * }
74
164
  */
75
165
  verify(tokenValue: Secret<string>): Promise<AccessToken | null>;
76
166
  /**
77
167
  * Invalidates a token identified by its publicly shared token
168
+ *
169
+ * @param tokenValue - The token value to invalidate
170
+ *
171
+ * @example
172
+ * const wasInvalidated = await provider.invalidate(new Secret('oat_abc123.def456'))
173
+ * if (wasInvalidated) {
174
+ * console.log('Token successfully invalidated')
175
+ * }
78
176
  */
79
177
  invalidate(tokenValue: Secret<string>): Promise<boolean>;
80
178
  }
@@ -2,8 +2,8 @@ import type { Secret } from '@adonisjs/core/helpers';
2
2
  import type { HttpContext } from '@adonisjs/core/http';
3
3
  import type { Exception } from '@adonisjs/core/exceptions';
4
4
  import type { LucidModel } from '@adonisjs/lucid/types/model';
5
- import type { AccessToken } from './access_token.js';
6
- import type { PROVIDER_REAL_USER } from '../../src/symbols.js';
5
+ import type { AccessToken } from './access_token.ts';
6
+ import type { PROVIDER_REAL_USER } from '../../src/symbols.ts';
7
7
  /**
8
8
  * Options accepted by the tokens provider that uses lucid
9
9
  * database service to fetch and persist tokens.
@@ -1,10 +1,19 @@
1
- import { Secret } from '@adonisjs/core/helpers';
2
- import { AccessToken } from '../access_token.js';
3
- import { PROVIDER_REAL_USER } from '../../../src/symbols.js';
4
- import type { LucidTokenable, AccessTokensGuardUser, AccessTokensUserProviderContract, AccessTokensLucidUserProviderOptions } from '../types.js';
1
+ import { type Secret } from '@adonisjs/core/helpers';
2
+ import { type AccessToken } from '../access_token.ts';
3
+ import { PROVIDER_REAL_USER } from '../../../src/symbols.ts';
4
+ import type { LucidTokenable, AccessTokensGuardUser, AccessTokensUserProviderContract, AccessTokensLucidUserProviderOptions } from '../types.ts';
5
5
  /**
6
6
  * Uses a lucid model to verify access tokens and find a user during
7
7
  * authentication
8
+ *
9
+ * @template TokenableProperty - The property name that holds the tokens provider
10
+ * @template UserModel - The Lucid model representing the user
11
+ *
12
+ * @example
13
+ * const userProvider = new AccessTokensLucidUserProvider({
14
+ * model: () => import('#models/user'),
15
+ * tokens: 'accessTokens'
16
+ * })
8
17
  */
9
18
  export declare class AccessTokensLucidUserProvider<TokenableProperty extends string, UserModel extends LucidTokenable<TokenableProperty>> implements AccessTokensUserProviderContract<InstanceType<UserModel>> {
10
19
  /**
@@ -16,6 +25,17 @@ export declare class AccessTokensLucidUserProvider<TokenableProperty extends str
16
25
  * Reference to the lazily imported model
17
26
  */
18
27
  protected model?: UserModel;
28
+ /**
29
+ * Creates a new AccessTokensLucidUserProvider instance
30
+ *
31
+ * @param options - Configuration options for the user provider
32
+ *
33
+ * @example
34
+ * const provider = new AccessTokensLucidUserProvider({
35
+ * model: () => import('#models/user'),
36
+ * tokens: 'accessTokens'
37
+ * })
38
+ */
19
39
  constructor(
20
40
  /**
21
41
  * Lucid provider options
@@ -24,18 +44,44 @@ export declare class AccessTokensLucidUserProvider<TokenableProperty extends str
24
44
  /**
25
45
  * Imports the model from the provider, returns and caches it
26
46
  * for further operations.
47
+ *
48
+ * @example
49
+ * const UserModel = await provider.getModel()
50
+ * const user = await UserModel.find(1)
27
51
  */
28
52
  protected getModel(): Promise<UserModel>;
29
53
  /**
30
54
  * Returns the tokens provider associated with the user model
55
+ *
56
+ * @example
57
+ * const tokensProvider = await provider.getTokensProvider()
58
+ * const token = await tokensProvider.create(user, ['read'])
31
59
  */
32
60
  protected getTokensProvider(): Promise<UserModel[TokenableProperty]>;
33
61
  /**
34
62
  * Creates an adapter user for the guard
63
+ *
64
+ * @param user - The user model instance
65
+ *
66
+ * @example
67
+ * const guardUser = await provider.createUserForGuard(user)
68
+ * console.log('User ID:', guardUser.getId())
69
+ * console.log('Original user:', guardUser.getOriginal())
35
70
  */
36
71
  createUserForGuard(user: InstanceType<UserModel>): Promise<AccessTokensGuardUser<InstanceType<UserModel>>>;
37
72
  /**
38
73
  * Create a token for a given user
74
+ *
75
+ * @param user - The user to create a token for
76
+ * @param abilities - Optional array of abilities the token should have
77
+ * @param options - Optional token configuration
78
+ *
79
+ * @example
80
+ * const token = await provider.createToken(user, ['read', 'write'], {
81
+ * name: 'API Token',
82
+ * expiresIn: '30d'
83
+ * })
84
+ * console.log('Created token:', token.value.release())
39
85
  */
40
86
  createToken(user: InstanceType<UserModel>, abilities?: string[] | undefined, options?: {
41
87
  name?: string;
@@ -43,15 +89,42 @@ export declare class AccessTokensLucidUserProvider<TokenableProperty extends str
43
89
  }): Promise<AccessToken>;
44
90
  /**
45
91
  * Invalidates a token identified by its publicly shared token
92
+ *
93
+ * @param tokenValue - The token value to invalidate
94
+ *
95
+ * @example
96
+ * const wasInvalidated = await provider.invalidateToken(
97
+ * new Secret('oat_abc123.def456')
98
+ * )
99
+ * console.log('Token invalidated:', wasInvalidated)
46
100
  */
47
101
  invalidateToken(tokenValue: Secret<string>): Promise<boolean>;
48
102
  /**
49
103
  * Finds a user by the user id
104
+ *
105
+ * @param identifier - The user identifier to search for
106
+ *
107
+ * @example
108
+ * const guardUser = await provider.findById(123)
109
+ * if (guardUser) {
110
+ * const originalUser = guardUser.getOriginal()
111
+ * console.log('Found user:', originalUser.email)
112
+ * }
50
113
  */
51
114
  findById(identifier: string | number | BigInt): Promise<AccessTokensGuardUser<InstanceType<UserModel>> | null>;
52
115
  /**
53
116
  * Verifies a publicly shared access token and returns an
54
117
  * access token for it.
118
+ *
119
+ * @param tokenValue - The token value to verify
120
+ *
121
+ * @example
122
+ * const token = await provider.verifyToken(
123
+ * new Secret('oat_abc123.def456')
124
+ * )
125
+ * if (token && !token.isExpired()) {
126
+ * console.log('Valid token with abilities:', token.abilities)
127
+ * }
55
128
  */
56
129
  verifyToken(tokenValue: Secret<string>): Promise<AccessToken | null>;
57
130
  }
@@ -1,9 +1,9 @@
1
1
  import type { HttpContext } from '@adonisjs/core/http';
2
2
  import type { ConfigProvider } from '@adonisjs/core/types';
3
- import { BasicAuthGuard } from './guard.js';
4
- import type { GuardConfigProvider } from '../../src/types.js';
5
- import { BasicAuthLucidUserProvider } from './user_providers/lucid.js';
6
- import type { LucidAuthenticatable, BasicAuthUserProviderContract, BasicAuthLucidUserProviderOptions } from './types.js';
3
+ import { BasicAuthGuard } from './guard.ts';
4
+ import type { GuardConfigProvider } from '../../src/types.ts';
5
+ import { BasicAuthLucidUserProvider } from './user_providers/lucid.ts';
6
+ import type { LucidAuthenticatable, BasicAuthUserProviderContract, BasicAuthLucidUserProviderOptions } from './types.ts';
7
7
  /**
8
8
  * Configures basic auth guard for authentication
9
9
  */
@@ -1,10 +1,23 @@
1
1
  import type { HttpContext } from '@adonisjs/core/http';
2
2
  import type { EmitterLike } from '@adonisjs/core/types/events';
3
- import type { AuthClientResponse, GuardContract } from '../../src/types.js';
4
- import { GUARD_KNOWN_EVENTS, PROVIDER_REAL_USER } from '../../src/symbols.js';
5
- import type { BasicAuthGuardEvents, BasicAuthUserProviderContract } from './types.js';
3
+ import type { AuthClientResponse, GuardContract } from '../../src/types.ts';
4
+ import { GUARD_KNOWN_EVENTS, type PROVIDER_REAL_USER } from '../../src/symbols.ts';
5
+ import type { BasicAuthGuardEvents, BasicAuthUserProviderContract } from './types.ts';
6
6
  /**
7
7
  * BasicAuth guard implements the HTTP Authentication protocol
8
+ *
9
+ * @template UserProvider - The user provider contract
10
+ *
11
+ * @example
12
+ * const guard = new BasicAuthGuard(
13
+ * 'basic',
14
+ * ctx,
15
+ * emitter,
16
+ * userProvider
17
+ * )
18
+ *
19
+ * const user = await guard.authenticate()
20
+ * console.log('Authenticated user:', user.email)
8
21
  */
9
22
  export declare class BasicAuthGuard<UserProvider extends BasicAuthUserProviderContract<unknown>> implements GuardContract<UserProvider[typeof PROVIDER_REAL_USER]> {
10
23
  #private;
@@ -1,3 +1,3 @@
1
- export { BasicAuthGuard } from './guard.js';
2
- export { basicAuthGuard, basicAuthUserProvider } from './define_config.js';
3
- export { BasicAuthLucidUserProvider } from './user_providers/lucid.js';
1
+ export { BasicAuthGuard } from './guard.ts';
2
+ export { BasicAuthLucidUserProvider } from './user_providers/lucid.ts';
3
+ export { basicAuthGuard, basicAuthUserProvider } from './define_config.ts';
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  E_UNAUTHORIZED_ACCESS
3
- } from "../../chunk-MUPAP5IP.js";
3
+ } from "../../chunk-S5G5RTJX.js";
4
4
  import "../../chunk-UXA4FHST.js";
5
5
 
6
6
  // modules/basic_auth_guard/guard.ts
@@ -157,6 +157,16 @@ var BasicAuthGuard = class {
157
157
  // modules/basic_auth_guard/user_providers/lucid.ts
158
158
  import { RuntimeException } from "@adonisjs/core/exceptions";
159
159
  var BasicAuthLucidUserProvider = class {
160
+ /**
161
+ * Creates a new BasicAuthLucidUserProvider instance
162
+ *
163
+ * @param options - Configuration options for the user provider
164
+ *
165
+ * @example
166
+ * const provider = new BasicAuthLucidUserProvider({
167
+ * model: () => import('#models/user')
168
+ * })
169
+ */
160
170
  constructor(options) {
161
171
  this.options = options;
162
172
  }
@@ -1,7 +1,7 @@
1
1
  import type { HttpContext } from '@adonisjs/core/http';
2
2
  import type { Exception } from '@adonisjs/core/exceptions';
3
3
  import type { LucidModel } from '@adonisjs/lucid/types/model';
4
- import type { PROVIDER_REAL_USER } from '../../src/symbols.js';
4
+ import type { PROVIDER_REAL_USER } from '../../src/symbols.ts';
5
5
  /**
6
6
  * A lucid model with verify credentials method to verify user
7
7
  * credentials during authentication.
@@ -1,8 +1,15 @@
1
- import { PROVIDER_REAL_USER } from '../../../src/symbols.js';
2
- import type { BasicAuthGuardUser, LucidAuthenticatable, BasicAuthUserProviderContract, BasicAuthLucidUserProviderOptions } from '../types.js';
1
+ import { PROVIDER_REAL_USER } from '../../../src/symbols.ts';
2
+ import type { BasicAuthGuardUser, LucidAuthenticatable, BasicAuthUserProviderContract, BasicAuthLucidUserProviderOptions } from '../types.ts';
3
3
  /**
4
4
  * Uses a Lucid model to verify access tokens and find a user during
5
5
  * authentication
6
+ *
7
+ * @template UserModel - The Lucid model representing the user
8
+ *
9
+ * @example
10
+ * const userProvider = new BasicAuthLucidUserProvider({
11
+ * model: () => import('#models/user')
12
+ * })
6
13
  */
7
14
  export declare class BasicAuthLucidUserProvider<UserModel extends LucidAuthenticatable> implements BasicAuthUserProviderContract<InstanceType<UserModel>> {
8
15
  /**
@@ -14,6 +21,16 @@ export declare class BasicAuthLucidUserProvider<UserModel extends LucidAuthentic
14
21
  * Reference to the lazily imported model
15
22
  */
16
23
  protected model?: UserModel;
24
+ /**
25
+ * Creates a new BasicAuthLucidUserProvider instance
26
+ *
27
+ * @param options - Configuration options for the user provider
28
+ *
29
+ * @example
30
+ * const provider = new BasicAuthLucidUserProvider({
31
+ * model: () => import('#models/user')
32
+ * })
33
+ */
17
34
  constructor(
18
35
  /**
19
36
  * Lucid provider options
@@ -1,9 +1,9 @@
1
1
  import type { HttpContext } from '@adonisjs/core/http';
2
2
  import type { ConfigProvider } from '@adonisjs/core/types';
3
- import { SessionGuard } from './guard.js';
4
- import type { GuardConfigProvider } from '../../src/types.js';
5
- import { SessionLucidUserProvider } from './user_providers/lucid.js';
6
- import type { SessionGuardOptions, LucidAuthenticatable, SessionUserProviderContract, SessionLucidUserProviderOptions, SessionWithTokensUserProviderContract } from './types.js';
3
+ import { SessionGuard } from './guard.ts';
4
+ import type { GuardConfigProvider } from '../../src/types.ts';
5
+ import { SessionLucidUserProvider } from './user_providers/lucid.ts';
6
+ import type { SessionGuardOptions, LucidAuthenticatable, SessionUserProviderContract, SessionLucidUserProviderOptions, SessionWithTokensUserProviderContract } from './types.ts';
7
7
  /**
8
8
  * Configures session tokens guard for authentication
9
9
  */
@@ -1,11 +1,26 @@
1
1
  import type { HttpContext } from '@adonisjs/core/http';
2
2
  import type { EmitterLike } from '@adonisjs/core/types/events';
3
- import type { AuthClientResponse, GuardContract } from '../../src/types.js';
4
- import { GUARD_KNOWN_EVENTS, PROVIDER_REAL_USER } from '../../src/symbols.js';
5
- import type { SessionGuardEvents, SessionGuardOptions, SessionUserProviderContract, SessionWithTokensUserProviderContract } from './types.js';
3
+ import type { AuthClientResponse, GuardContract } from '../../src/types.ts';
4
+ import { GUARD_KNOWN_EVENTS, type PROVIDER_REAL_USER } from '../../src/symbols.ts';
5
+ import type { SessionGuardEvents, SessionGuardOptions, SessionUserProviderContract, SessionWithTokensUserProviderContract } from './types.ts';
6
6
  /**
7
7
  * Session guard uses AdonisJS session store to track logged-in
8
8
  * user information.
9
+ *
10
+ * @template UseRememberTokens - Whether the guard supports remember me tokens
11
+ * @template UserProvider - The user provider contract
12
+ *
13
+ * @example
14
+ * const guard = new SessionGuard(
15
+ * 'web',
16
+ * ctx,
17
+ * { useRememberMeTokens: true },
18
+ * emitter,
19
+ * userProvider
20
+ * )
21
+ *
22
+ * const user = await guard.authenticate()
23
+ * console.log('Authenticated user:', user.email)
9
24
  */
10
25
  export declare class SessionGuard<UseRememberTokens extends boolean, UserProvider extends UseRememberTokens extends true ? SessionWithTokensUserProviderContract<unknown> : SessionUserProviderContract<unknown>> implements GuardContract<UserProvider[typeof PROVIDER_REAL_USER]> {
11
26
  #private;
@@ -57,12 +72,36 @@ export declare class SessionGuard<UseRememberTokens extends boolean, UserProvide
57
72
  /**
58
73
  * The key used to store the logged-in user id inside
59
74
  * session
75
+ *
76
+ * @example
77
+ * console.log('Session key:', guard.sessionKeyName) // 'auth_web'
60
78
  */
61
79
  get sessionKeyName(): string;
62
80
  /**
63
81
  * The key used to store the remember me token cookie
82
+ *
83
+ * @example
84
+ * console.log('Remember me key:', guard.rememberMeKeyName) // 'remember_web'
64
85
  */
65
86
  get rememberMeKeyName(): string;
87
+ /**
88
+ * Creates a new SessionGuard instance
89
+ *
90
+ * @param name - Unique name for the guard instance
91
+ * @param ctx - HTTP context for the current request
92
+ * @param options - Configuration options for the session guard
93
+ * @param emitter - Event emitter for guard events
94
+ * @param userProvider - User provider for authentication
95
+ *
96
+ * @example
97
+ * const guard = new SessionGuard(
98
+ * 'web',
99
+ * ctx,
100
+ * { useRememberMeTokens: true, rememberMeTokensAge: '30d' },
101
+ * emitter,
102
+ * userProvider
103
+ * )
104
+ */
66
105
  constructor(name: string, ctx: HttpContext, options: SessionGuardOptions<UseRememberTokens>, emitter: EmitterLike<SessionGuardEvents<UserProvider[typeof PROVIDER_REAL_USER]>>, userProvider: UserProvider);
67
106
  /**
68
107
  * Returns an instance of the authenticated user. Or throws
@@ -1,5 +1,5 @@
1
- export { RememberMeToken } from './remember_me_token.js';
2
- export { SessionGuard } from './guard.js';
3
- export { DbRememberMeTokensProvider } from './token_providers/db.js';
4
- export { sessionGuard, sessionUserProvider } from './define_config.js';
5
- export { SessionLucidUserProvider } from './user_providers/lucid.js';
1
+ export { SessionGuard } from './guard.ts';
2
+ export { RememberMeToken } from './remember_me_token.ts';
3
+ export { DbRememberMeTokensProvider } from './token_providers/db.ts';
4
+ export { SessionLucidUserProvider } from './user_providers/lucid.ts';
5
+ export { sessionGuard, sessionUserProvider } from './define_config.ts';