async function createAccessDb() {
  const dbs = await cloudant.db.list()
  if (dbs.includes(dbName)) {
    console.info('Database already exists: %s', dbName)
  } else {
    console.info('Creating database: %s', dbName)
    await cloudant.db.create(dbName)
  }
  const accessDb = cloudant.db.use(dbName)

  // Index corresponds to the search which includes (where not used and expiresAt < now)
  await accessDb.index({
    name: 'oneTimePassword',
    type: 'json',
    index: {
      fields: [
        'used',
        'expiresAt'
      ]
    }
  })

  return accessDb
}
// Create the access database (storing codes/tokens) and establishing its indexes
Create the access database (storing codes/tokens) and establishing its indexes
Create the access database ( storing codes / tokens ) and establishing its indexes
async function createAccessDb() {
  const dbs = await cloudant.db.list()
  if (dbs.includes(dbName)) {
    console.info('Database already exists: %s', dbName)
  } else {
    console.info('Creating database: %s', dbName)
    await cloudant.db.create(dbName)
  }
  const accessDb = cloudant.db.use(dbName)
  await accessDb.index({
    name: 'oneTimePassword',
    type: 'json',
    index: {
      fields: [
        'used',
        'expiresAt'
      ]
    }
  })
  return accessDb
}
async function createAccessDb ( ) { const dbs = await cloudant . db . list ( ) if ( dbs . includes ( dbName ) ) { console . info ( 'Database already exists: %s' , dbName ) } else { console . info ( 'Creating database: %s' , dbName ) await cloudant . db . create ( dbName ) } const accessDb = cloudant . db . use ( dbName ) await accessDb . index ( { name : 'oneTimePassword' , type : 'json' , index : { fields : [ 'used' , 'expiresAt' ] } } ) return accessDb }
Create the access database (storing codes/tokens) and establishing its indexes
Create the access database ( storing codes / tokens ) and establishing its indexes
// Index corresponds to the search which includes (where not used and expiresAt < now)