next-password-protect icon indicating copy to clipboard operation
next-password-protect copied to clipboard

bypassProtection example

Open stvgale opened this issue 2 years ago • 1 comments

Having trouble understanding how to use "bypassProtection". An example of this would be helpful.

stvgale avatar Feb 28 '23 17:02 stvgale

Hey. It's meant to be able to have some pages (routes) that will not have this password protection applied. To use this, just add property to withPasswordProtect:

withPasswordProtect(MyApp, {
  ...
  bypassProtection: (route) => {
    return route.pathname === '/specific-page/that-doesnt-need-protection' || route.pathname === '/some-other-page'
  }
})

In this example, pages with route /specific-page/that-doesnt-need-protection and /some-other-page will not be protected by password.

route is just object retrieved from useRouter, so you can use all its properties offered from NextJS.

charamza avatar Mar 05 '23 16:03 charamza