This commit is contained in:
33
lib/passport.provider.ts
Normal file
33
lib/passport.provider.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import type { Provider } from '@nestjs/common'
|
||||
|
||||
import { PASSPORT_OPTIONS } from './constants'
|
||||
import type { PassportAsyncOptions, PassportOptions } from './interfaces'
|
||||
|
||||
export function createPassportOptionsProvider(
|
||||
options: PassportOptions
|
||||
): Provider {
|
||||
return {
|
||||
provide: PASSPORT_OPTIONS,
|
||||
useValue: Object.freeze({ ...options })
|
||||
}
|
||||
}
|
||||
|
||||
export function createPassportAsyncOptionsProvider(
|
||||
options: PassportAsyncOptions
|
||||
): Provider {
|
||||
return {
|
||||
provide: PASSPORT_OPTIONS,
|
||||
useFactory: async (...args: any[]) => {
|
||||
const resolved = await options.useFactory!(...args)
|
||||
|
||||
if (!resolved || typeof resolved.secretKey !== 'string') {
|
||||
throw new Error(
|
||||
'[Passport Module] "secretKey" обязателен для заполнения и должен быть строкой.'
|
||||
)
|
||||
}
|
||||
|
||||
return Object.freeze({ ...resolved })
|
||||
},
|
||||
inject: options.inject ?? []
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user