Skip to content

Commit

Permalink
Merge pull request #2 from mdsadique-inam/develop
Browse files Browse the repository at this point in the history
fixed incorrect config resolve
  • Loading branch information
brunolipe-a committed May 14, 2024
2 parents a0bc328 + b7698b5 commit c5dc5c6
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions providers/two_factor_auth_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type { ApplicationService } from '@adonisjs/core/types'

import { TwoFactorAuthManager } from '../src/two_factor_auth_manager.js'
import { ResolvedTwoFactorAuthConfig } from '../src/types.js'
import { configProvider } from '@adonisjs/core'
import { RuntimeException } from '@adonisjs/core/exceptions'

/**
* Extending AdonisJS types
Expand All @@ -19,8 +21,18 @@ export default class TwoFactorAuthProvider {
* Register bindings to the container
*/
register() {
this.app.container.singleton('two_factor_auth', () => {
const config = this.app.config.get<ResolvedTwoFactorAuthConfig>('2fa')
this.app.container.singleton('two_factor_auth', async () => {
const twoFactorConfigProvider = this.app.config.get<ResolvedTwoFactorAuthConfig>('2fa')

/**
* Resolve config from the provider
*/
const config = await configProvider.resolve<any>(this.app, twoFactorConfigProvider)
if (!config) {
throw new RuntimeException(
'Invalid "config/2fa.ts" file. Make sure you are using the "defineConfig" method'
)
}

return new TwoFactorAuthManager(config)
})
Expand Down

0 comments on commit c5dc5c6

Please sign in to comment.