-
-
Notifications
You must be signed in to change notification settings - Fork 63
/
configure.ts
65 lines (60 loc) · 1.49 KB
/
configure.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* @adonisjs/auth
*
* (c) AdonisJS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { presetAuth } from '@adonisjs/presets/auth'
import type Configure from '@adonisjs/core/commands/configure'
/**
* Configures the auth package
*/
export async function configure(command: Configure) {
const codemods = await command.createCodemods()
let guard: string | undefined = command.parsedFlags.guard
/**
* Prompts user to select a guard when not mentioned via
* the CLI
*/
if (guard === undefined) {
guard = await command.prompt.choice(
'Select the auth guard you want to use',
[
{
name: 'session',
message: 'Session',
},
{
name: 'access_tokens',
message: 'Opaque access tokens',
},
{
name: 'basic_auth',
message: 'Basic Auth',
},
],
{
validate(value) {
return !!value
},
}
)
}
/**
* Ensure selected or guard defined via the CLI flag is
* valid
*/
if (!['session', 'access_tokens', 'basic_auth'].includes(guard!)) {
command.logger.error(
`The selected guard "${guard}" is invalid. Select one from: session, access_tokens, basic_auth`
)
command.exitCode = 1
return
}
await presetAuth(codemods, command.app, {
guard: guard as 'session' | 'access_tokens' | 'basic_auth',
userProvider: 'lucid',
})
}