Skip to content

Commit

Permalink
refactor: simplify initial setup
Browse files Browse the repository at this point in the history
We do not create any config file by default. Ask the user to go
through the docs and setup config file as per the guards they
want to use
  • Loading branch information
thetutlage committed Oct 25, 2023
1 parent 53ce132 commit ab0735d
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 130 deletions.
23 changes: 0 additions & 23 deletions configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,10 @@

import type Configure from '@adonisjs/core/commands/configure'

/**
* Configures the user provider to use for finding
* users
*/
async function configureProvider(command: Configure) {
const provider = await command.prompt.choice('Select the user provider you want to use', [
{
name: 'lucid',
message: 'Lucid models',
},
{
name: 'db',
message: 'Database query builder',
},
])

/**
* Publish config file
*/
await command.publishStub('config.stub', { provider })
}

/**
* Configures the auth package
*/
export async function configure(command: Configure) {
await configureProvider(command)
const codemods = await command.createCodemods()

/**
Expand Down
42 changes: 0 additions & 42 deletions stubs/config.stub

This file was deleted.

66 changes: 1 addition & 65 deletions tests/auth/configure.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test.group('Configure', (group) => {
context.fs.basePath = fileURLToPath(BASE_URL)
})

test('create config file and register provider', async ({ fs, assert }) => {
test('register provider', async ({ fs, assert }) => {
const ignitor = new IgnitorFactory()
.withCoreProviders()
.withCoreConfig()
Expand All @@ -44,72 +44,10 @@ test.group('Configure', (group) => {

const ace = await app.container.make('ace')
const command = await ace.create(Configure, ['../../../index.js'])
command.prompt.trap('Select the user provider you want to use').replyWith('lucid')
await command.exec()

await assert.fileExists('config/auth.ts')
await assert.fileExists('adonisrc.ts')
await assert.fileContains('adonisrc.ts', '@adonisjs/auth/auth_provider')
await assert.fileContains(
'config/auth.ts',
`const userProvider = providers.lucid({
model: () => import('#models/user'),
uids: ['email'],
})`
)
await assert.fileContains(
'config/auth.ts',
`declare module '@adonisjs/auth/types' {
interface Authenticators extends InferAuthenticators<typeof authConfig> {}
}`
)
}).timeout(60 * 1000)

test('create config file with db user provider', async ({ fs, assert }) => {
const ignitor = new IgnitorFactory()
.withCoreProviders()
.withCoreConfig()
.create(BASE_URL, {
importer: (filePath) => {
if (filePath.startsWith('./') || filePath.startsWith('../')) {
return import(new URL(filePath, BASE_URL).href)
}

return import(filePath)
},
})

await fs.create('start/kernel.ts', `router.use([])`)
await fs.createJson('tsconfig.json', {})
await fs.create('adonisrc.ts', `export default defineConfig({}) {}`)

const app = ignitor.createApp('web')
await app.init()
await app.boot()

const ace = await app.container.make('ace')
const command = await ace.create(Configure, ['../../../index.js'])
command.prompt.trap('Select the user provider you want to use').replyWith('db')
await command.exec()

await assert.fileExists('config/auth.ts')
await assert.fileExists('adonisrc.ts')
await assert.fileContains('adonisrc.ts', '@adonisjs/auth/auth_provider')
await assert.fileContains(
'config/auth.ts',
`const userProvider = providers.db({
table: 'users',
passwordColumnName: 'password',
id: 'id',
uids: ['email'],
})`
)
await assert.fileContains(
'config/auth.ts',
`declare module '@adonisjs/auth/types' {
interface Authenticators extends InferAuthenticators<typeof authConfig> {}
}`
)
}).timeout(60 * 1000)

test('register middleware', async ({ fs, assert }) => {
Expand Down Expand Up @@ -143,10 +81,8 @@ test.group('Configure', (group) => {

const ace = await app.container.make('ace')
const command = await ace.create(Configure, ['../../../index.js'])
command.prompt.trap('Select the user provider you want to use').replyWith('db')
await command.exec()

await assert.fileExists('config/auth.ts')
await assert.fileExists('adonisrc.ts')
await assert.fileExists('app/middleware/auth_middleware.ts')
await assert.fileExists('app/middleware/guest_middleware.ts')
Expand Down

0 comments on commit ab0735d

Please sign in to comment.