@adonisjs/auth 9.0.0-4 → 9.0.0-5

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.
@@ -6,31 +6,10 @@
6
6
  * For the full copyright and license information, please view the LICENSE
7
7
  * file that was distributed with this source code.
8
8
  */
9
- /**
10
- * Configures the user provider to use for finding
11
- * users
12
- */
13
- async function configureProvider(command) {
14
- const provider = await command.prompt.choice('Select the user provider you want to use', [
15
- {
16
- name: 'lucid',
17
- message: 'Lucid models',
18
- },
19
- {
20
- name: 'db',
21
- message: 'Database query builder',
22
- },
23
- ]);
24
- /**
25
- * Publish config file
26
- */
27
- await command.publishStub('config.stub', { provider });
28
- }
29
9
  /**
30
10
  * Configures the auth package
31
11
  */
32
12
  export async function configure(command) {
33
- await configureProvider(command);
34
13
  const codemods = await command.createCodemods();
35
14
  /**
36
15
  * Publish middleware to user application
package/build/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { configure } from './configure.js';
2
2
  export { stubsRoot } from './stubs/main.js';
3
- export * as errors from './src/auth/errors.js';
4
3
  export * as symbols from './src/auth/symbols.js';
5
4
  export { AuthManager } from './src/auth/auth_manager.js';
6
5
  export { Authenticator } from './src/auth/authenticator.js';
7
6
  export { defineConfig, providers } from './src/auth/define_config.js';
7
+ export { AuthenticationException, InvalidCredentialsException } from './src/auth/errors.js';
package/build/index.js CHANGED
@@ -8,8 +8,8 @@
8
8
  */
9
9
  export { configure } from './configure.js';
10
10
  export { stubsRoot } from './stubs/main.js';
11
- export * as errors from './src/auth/errors.js';
12
11
  export * as symbols from './src/auth/symbols.js';
13
12
  export { AuthManager } from './src/auth/auth_manager.js';
14
13
  export { Authenticator } from './src/auth/authenticator.js';
15
14
  export { defineConfig, providers } from './src/auth/define_config.js';
15
+ export { AuthenticationException, InvalidCredentialsException } from './src/auth/errors.js';
@@ -5,6 +5,8 @@ import { HttpContext } from '@adonisjs/core/http';
5
5
  * made to authenticate an HTTP request
6
6
  */
7
7
  export declare class AuthenticationException extends Exception {
8
+ static status?: number | undefined;
9
+ static code?: string | undefined;
8
10
  /**
9
11
  * Raises authentication exception when session guard
10
12
  * is unable to authenticate the request
@@ -49,6 +51,7 @@ export declare class AuthenticationException extends Exception {
49
51
  export declare class InvalidCredentialsException extends Exception {
50
52
  static message: string;
51
53
  static code: string;
54
+ static status?: number | undefined;
52
55
  static E_INVALID_CREDENTIALS(guardDriverName: string): InvalidCredentialsException;
53
56
  guardDriverName: string;
54
57
  identifier: string;
@@ -12,6 +12,8 @@ import { Exception } from '@poppinss/utils';
12
12
  * made to authenticate an HTTP request
13
13
  */
14
14
  export class AuthenticationException extends Exception {
15
+ static status = 401;
16
+ static code = 'E_UNAUTHORIZED_ACCESS';
15
17
  /**
16
18
  * Raises authentication exception when session guard
17
19
  * is unable to authenticate the request
@@ -103,6 +105,7 @@ export class AuthenticationException extends Exception {
103
105
  export class InvalidCredentialsException extends Exception {
104
106
  static message = 'Invalid credentials';
105
107
  static code = 'E_INVALID_CREDENTIALS';
108
+ static status = 400;
106
109
  static E_INVALID_CREDENTIALS(guardDriverName) {
107
110
  return new InvalidCredentialsException(InvalidCredentialsException.message, {
108
111
  guardDriverName,
@@ -64,12 +64,16 @@ export type InferAuthenticators<Config extends ConfigProvider<{
64
64
  default: unknown;
65
65
  guards: unknown;
66
66
  }>> = Awaited<ReturnType<Config['resolver']>>['guards'];
67
+ /**
68
+ * Helper to convert union to intersection
69
+ */
70
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
67
71
  /**
68
72
  * Infer events based upon the configure authenticators
69
73
  */
70
- export type InferAuthEvents<KnownAuthenticators extends Record<string, GuardFactory>> = {
74
+ export type InferAuthEvents<KnownAuthenticators extends Record<string, GuardFactory>> = UnionToIntersection<{
71
75
  [K in keyof KnownAuthenticators]: ReturnType<KnownAuthenticators[K]>[typeof GUARD_KNOWN_EVENTS];
72
- }[keyof KnownAuthenticators];
76
+ }[keyof KnownAuthenticators]>;
73
77
  /**
74
78
  * Auth service is a singleton instance of the AuthManager
75
79
  * configured using the config stored within the user
@@ -83,3 +87,4 @@ export interface AuthService extends AuthManager<Authenticators extends Record<s
83
87
  export type GuardConfigProvider<Guard extends GuardFactory> = {
84
88
  resolver: (name: string, app: ApplicationService) => Promise<Guard>;
85
89
  };
90
+ export {};
@@ -11,7 +11,7 @@ type DatabaseTokenRow = {
11
11
  created_at: Date;
12
12
  updated_at: Date;
13
13
  expires_at: Date | null;
14
- };
14
+ } & Record<string, any>;
15
15
  /**
16
16
  * A generic implementation to read tokens from the database
17
17
  */
@@ -1,4 +1,4 @@
1
- import { Exception } from '@poppinss/utils';
1
+ import type { Exception } from '@poppinss/utils';
2
2
  import type { RememberMeToken } from './token.js';
3
3
  import type { UserProviderContract, TokenProviderContract, DatabaseTokenProviderOptions } from '../../core/types.js';
4
4
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonisjs/auth",
3
- "version": "9.0.0-4",
3
+ "version": "9.0.0-5",
4
4
  "description": "Official authentication provider for Adonis framework",
5
5
  "type": "module",
6
6
  "main": "build/index.js",
@@ -1,42 +0,0 @@
1
- {{{
2
- exports({ to: app.configPath('auth.ts') })
3
- }}}
4
- import { defineConfig, providers } from '@adonisjs/auth'
5
- import { InferAuthEvents, Authenticators } from '@adonisjs/auth/types'
6
- {{#if provider === 'lucid'}}
7
- /**
8
- * Using the "models/user" model to find users during
9
- * login and authentication
10
- */
11
- const userProvider = providers.lucid({
12
- model: () => import('#models/user'),
13
- uids: ['email'],
14
- })
15
- {{/if}}
16
- {{#if provider === 'db'}}
17
- /**
18
- * Using Lucid query builder to directly query the database
19
- * to find users during login and authentication.
20
- */
21
- const userProvider = providers.db({
22
- table: 'users',
23
- passwordColumnName: 'password',
24
- id: 'id',
25
- uids: ['email'],
26
- })
27
- {{/if}}
28
-
29
- const authConfig = defineConfig({
30
- default: 'web',
31
- guards: {
32
- web: {} // to be configured
33
- }
34
- })
35
-
36
- export default authConfig
37
- declare module '@adonisjs/auth/types' {
38
- interface Authenticators extends InferAuthenticators<typeof authConfig> {}
39
- }
40
- declare module '@adonisjs/core/types' {
41
- interface EventsList extends InferAuthEvents<Authenticators> {}
42
- }