Search code examples
postgresqlnestjstypeormjoi

Configure a Next JS authentication using joi


I am trying to do an autentification using JWT and I need joi here:

import Joi from 'joi';
@Module({
  imports: [
...
    TypeOrmModule.forRoot(),
    ConfigModule.forRoot({
      validationSchema: Joi.object({
      JWT_SECRET: Joi.string().required(),
      JWT_EXPIRATION_TIME: Joi.string().required(),
    })})
]

but I don't really know how to declare it and I have this error:

validationSchema: joi_1.default.object({
TypeError: Cannot read property 'object' of undefined

And this is where i got Joi

    "joi": {
      "version": "17.4.0",
      "resolved": "https://registry.npmjs.org/joi/-/joi-17.4.0.tgz",
      "integrity": "sha512-F4WiW2xaV6wc1jxete70Rw4V/VuMd6IN+a5ilZsxG4uYtUXWu2kq9W5P2dz30e7Gmw8RCbY/u/uk+dMPma9tAg==",
      "requires": {
        "@hapi/hoek": "^9.0.0",
        "@hapi/topo": "^5.0.0",
        "@sideway/address": "^4.1.0",
        "@sideway/formula": "^3.0.0",
        "@sideway/pinpoint": "^2.0.0"
      }

I think I am missing something, but I am new in this.


Solution

  • Instead of import Joi from 'joi'; use import * as Joi from 'joi';