Skip to content

Add a middleware to be able to lock pages behind a password

License

Notifications You must be signed in to change notification settings

truesteps/nuxt-website-lock

Repository files navigation

nuxt-website-lock

npm version npm downloads Github Actions CI License

📖 Release Notes

Setup

  1. Add nuxt-website-lock dependency to your project
yarn add nuxt-website-lock # or npm install nuxt-website-lock
  1. Add nuxt-website-lock to the modules section of nuxt.config.js
{
  modules: [
    // Simple usage
    'nuxt-website-lock',

    // website-lock has to be before axios so axios instance is available at websitelock module
    // to enable validation of token on BE change "enableServerValidation" to true
    ['nuxt-website-lock', { enableServerValidation: false, enabled: true, password: 'superSecretPassword' }],
    '@nuxtjs/axios',
  ]
}

Usage

After setting up the options properly, all you need to do is apply the WebsiteLock route middleware to the page(s), which should be locked

Module options

Option name Description Default value Possible values
enabled whether website lock should be enabled default: null options: true/false
password password which unlocks website default: null any string (will be simply hashed to md5)
formPath url at which the form for website lock will be default: /website-lock any string starting with slash
enableServerValidation whether password should be validated against BE (tailor fitted for personal use, will be expanded upon in later versions) default: false options: true/false
cookieName name of the cookie under which the hashed token will be stored default: websiteLock._token any string, cannot be null
cookie object storing some cookie
cookie.prefix prefix of cookieName being stored default: '' any string, cannot be null
cookie.expires number of days in which the cookie will expire default: 2 any unsigned integer

Todo

  • better customizability

Development

  1. Clone this repository
  2. Install dependencies using yarn install or npm install
  3. Start development server using npm run dev

License

MIT License

Copyright (c) Patrik Jánosdeák