@adonisjs/auth 9.0.0-1 → 9.0.0-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/build/configure.js +15 -0
- package/build/src/auth/auth_manager.d.ts +1 -0
- package/build/src/auth/authenticator.d.ts +2 -1
- package/build/src/auth/authenticator.js +1 -1
- package/build/src/auth/define_config.d.ts +2 -0
- package/build/src/auth/define_config.js +1 -0
- package/build/src/auth/middleware/auth_middleware.d.ts +1 -1
- package/build/stubs/config.stub +5 -1
- package/build/stubs/guards/session.stub +21 -0
- package/package.json +2 -2
package/build/configure.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
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
|
+
import { stubsRoot } from './index.js';
|
|
9
10
|
/**
|
|
10
11
|
* Configures the user provider to use for finding
|
|
11
12
|
* users
|
|
@@ -26,10 +27,24 @@ async function configureProvider(command) {
|
|
|
26
27
|
*/
|
|
27
28
|
await command.publishStub('config.stub', { provider });
|
|
28
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Configures the session guard and output its config
|
|
32
|
+
* to the console
|
|
33
|
+
*/
|
|
34
|
+
async function configureSessionGuard(command) {
|
|
35
|
+
const tokens = await command.prompt.confirm('Do you want to use remember me tokens?');
|
|
36
|
+
const stubs = await command.app.stubs.create();
|
|
37
|
+
const stub = await stubs.build('guards/session.stub', { source: stubsRoot });
|
|
38
|
+
const { contents } = await stub.prepare({ tokens });
|
|
39
|
+
command.logger.log(contents);
|
|
40
|
+
}
|
|
29
41
|
/**
|
|
30
42
|
* Configures the auth package
|
|
31
43
|
*/
|
|
32
44
|
export async function configure(command) {
|
|
45
|
+
if (command.parsedFlags && command.parsedFlags.guard === 'session') {
|
|
46
|
+
return configureSessionGuard(command);
|
|
47
|
+
}
|
|
33
48
|
await configureProvider(command);
|
|
34
49
|
const codemods = await command.createCodemods();
|
|
35
50
|
/**
|
|
@@ -33,6 +33,7 @@ export declare class Authenticator<KnownGuards extends Record<string, GuardFacto
|
|
|
33
33
|
get authenticationAttempted(): boolean;
|
|
34
34
|
constructor(ctx: HttpContext, config: {
|
|
35
35
|
default: keyof KnownGuards;
|
|
36
|
+
loginRoute: string;
|
|
36
37
|
guards: KnownGuards;
|
|
37
38
|
});
|
|
38
39
|
/**
|
|
@@ -51,6 +52,6 @@ export declare class Authenticator<KnownGuards extends Record<string, GuardFacto
|
|
|
51
52
|
* Otherwise, "AuthenticationException" will be raised.
|
|
52
53
|
*/
|
|
53
54
|
authenticateUsing(guards?: (keyof KnownGuards)[], options?: {
|
|
54
|
-
|
|
55
|
+
loginRoute?: string;
|
|
55
56
|
}): Promise<boolean>;
|
|
56
57
|
}
|
|
@@ -116,7 +116,7 @@ export class Authenticator {
|
|
|
116
116
|
throw new AuthenticationException('Unauthorized access', {
|
|
117
117
|
code: 'E_UNAUTHORIZED_ACCESS',
|
|
118
118
|
guardDriverName: lastUsedGuardDriver,
|
|
119
|
-
redirectTo: options?.
|
|
119
|
+
redirectTo: options?.loginRoute || this.#config.loginRoute,
|
|
120
120
|
});
|
|
121
121
|
}
|
|
122
122
|
}
|
|
@@ -7,6 +7,7 @@ import type { LucidAuthenticatable, LucidUserProviderOptions, DatabaseUserProvid
|
|
|
7
7
|
*/
|
|
8
8
|
export type ResolvedAuthConfig<KnownGuards extends Record<string, GuardFactory | GuardConfigProvider<GuardFactory>>> = {
|
|
9
9
|
default: keyof KnownGuards;
|
|
10
|
+
loginRoute: string;
|
|
10
11
|
guards: {
|
|
11
12
|
[K in keyof KnownGuards]: KnownGuards[K] extends GuardConfigProvider<infer A> ? A : KnownGuards[K];
|
|
12
13
|
};
|
|
@@ -18,6 +19,7 @@ export type ResolvedAuthConfig<KnownGuards extends Record<string, GuardFactory |
|
|
|
18
19
|
*/
|
|
19
20
|
export declare function defineConfig<KnownGuards extends Record<string, GuardFactory | GuardConfigProvider<GuardFactory>>>(config: {
|
|
20
21
|
default: keyof KnownGuards;
|
|
22
|
+
loginRoute: string;
|
|
21
23
|
guards: KnownGuards;
|
|
22
24
|
}): ConfigProvider<ResolvedAuthConfig<KnownGuards>>;
|
|
23
25
|
/**
|
|
@@ -6,7 +6,7 @@ import type { Authenticators } from '@adonisjs/auth/types';
|
|
|
6
6
|
*/
|
|
7
7
|
export type AuthMiddlewareOptions = {
|
|
8
8
|
guards?: (keyof Authenticators)[];
|
|
9
|
-
|
|
9
|
+
loginRoute?: string;
|
|
10
10
|
};
|
|
11
11
|
export default class AuthMiddleware {
|
|
12
12
|
handle(ctx: HttpContext, next: NextFn, options?: AuthMiddlewareOptions): Promise<any>;
|
package/build/stubs/config.stub
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({
|
|
3
|
+
to: app.makePath('config/auth.ts')
|
|
4
|
+
})
|
|
5
|
+
}}}
|
|
6
|
+
{{#if tokens}}
|
|
7
|
+
import { sessionGuard, tokensProvider } from '@adonisjs/auth/session'
|
|
8
|
+
{{#else}}
|
|
9
|
+
import { sessionGuard } from '@adonisjs/auth/session'
|
|
10
|
+
{{/if}}
|
|
11
|
+
|
|
12
|
+
{
|
|
13
|
+
web: sessionGuard({
|
|
14
|
+
provider: userProvider,
|
|
15
|
+
{{#if tokens}}
|
|
16
|
+
tokens: tokensProvider.db({
|
|
17
|
+
table: 'remember_me_tokens'
|
|
18
|
+
})
|
|
19
|
+
{{/if}}
|
|
20
|
+
})
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/auth",
|
|
3
|
-
"version": "9.0.0-
|
|
3
|
+
"version": "9.0.0-3",
|
|
4
4
|
"description": "Official authentication provider for Adonis framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "build/index.js",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@adonisjs/assembler": "^6.1.3-25",
|
|
69
|
-
"@adonisjs/core": "^6.1.5-
|
|
69
|
+
"@adonisjs/core": "^6.1.5-31",
|
|
70
70
|
"@adonisjs/eslint-config": "^1.1.8",
|
|
71
71
|
"@adonisjs/i18n": "^2.0.0-6",
|
|
72
72
|
"@adonisjs/lucid": "^19.0.0-3",
|