Gathering detailed insights and metrics for @storyofams/next-password-protect
Gathering detailed insights and metrics for @storyofams/next-password-protect
npm install @storyofams/next-password-protect
Typescript
Module System
Node Version
NPM Version
35.9
Supply Chain
79.5
Quality
78.3
Maintenance
50
Vulnerability
91.6
License
TypeScript (81.65%)
JavaScript (15.38%)
CSS (2.88%)
Shell (0.09%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
351,922
Last Day
48
Last Week
289
Last Month
1,304
Last Year
31,038
318 Stars
125 Commits
18 Forks
6 Watching
17 Branches
9 Contributors
Minified
Minified + Gzipped
Latest Version
1.7.0
Package Id
@storyofams/next-password-protect@1.7.0
Unpacked Size
647.33 kB
Size
146.97 kB
File Count
324
NPM Version
6.14.11
Node Version
12.22.12
Cumulative downloads
Total Downloads
Last day
-5.9%
48
Compared to previous day
Last week
-6.5%
289
Compared to previous week
Last month
-8.9%
1,304
Compared to previous month
Last year
-66.9%
31,038
Compared to previous year
3
77
Password protect your Next.js deployments. View demo (Password is secret)
This library adds a password prompt to your Next.js deployment. It consists of two main parts:
Important: The recommended use case for this library is in a staging or preview environment. By taking advantage of webpack's DefinePlugin
, we can make sure this library is only included in certain environments, keeping the production bundle size small.
This library is NOT meant as a secure password authentication wrapper, but rather as a way to keep nosey people out.
1yarn add @storyofams/next-password-protect 2# or 3npm install @storyofams/next-password-protect
There are 3 steps to enabling password protect: setting a global variable, adding the API routes, and adding the HOC to _app.
In order to be able to take advantage of dead code elimination, it is recommended to add an environment variable like process.env.PASSWORD_PROTECT
, and enable the library based on that variable. To set this variable, add the following to next.config.js
:
1module.exports = { 2 env: { 3 // Add any logic you want here, returning `true` to enable password protect. 4 PASSWORD_PROTECT: process.env.ENVIRONMENT === 'staging', 5 } 6});
Add two api routes, one with the loginHandler
and one with the passwordCheckHandler
api function. You can name them anything, as long as you pass the names to loginApiUrl
and checkApiUrl
respectively, in the next step. By default it expects /login
and /passwordCheck
.
1import { loginHandler } from "@storyofams/next-password-protect"; 2 3export default loginHandler("YOUR_SECRET_PASSWORD", { 4 // Options go here (optional) 5 cookieName: "next-password-protect", 6});
1import { passwordCheckHandler } from "@storyofams/next-password-protect"; 2 3export default passwordCheckHandler("YOUR_SECRET_PASSWORD", { 4 // Options go here (optional) 5 cookieName: "next-password-protect", 6});
Add the withPasswordProtect
HOC to the default export of App
in pages/_app.tsx
:
1import { withPasswordProtect } from "@storyofams/next-password-protect"; 2 3// Before: export default App; 4export default process.env.PASSWORD_PROTECT 5 ? withPasswordProtect(App, { 6 // Options go here (optional) 7 loginApiUrl: "/login", 8 }) 9 : App;
Note: make sure to specify loginApiUrl
and/or checkApiUrl
if the api route(s) are not default.
loginHandler(password: string, options)
The options object can contain any of the following options:
Option | Description | Default value |
---|---|---|
cookieMaxAge | Cookie Max-Age attribute | undefined |
cookieName | The name of the authorization cookie | 'next-password-protect' |
cookieSameSite | SameSite cookie attribute | false |
cookieSecure | Secure flag on the cookie | process.env.NODE_ENV === 'production' |
passwordCheckHandler(password: string, options)
The options object can contain any of the following options:
Option | Description | Default value |
---|---|---|
cookieName | The name of the authorization cookie | 'next-password-protect' |
withPasswordProtect(App: NextApp, options)
The options object can contain any of the following options:
Option | Description | Default value |
---|---|---|
checkApiUrl | Relative path of the api route handled by passwordCheckHandler | '/api/passwordCheck' |
loginApiUrl | Relative path of the api route handled by loginHandler | '/api/login' |
loginComponent | Supply your own React component to show as login prompt | LoginComponent |
loginComponentProps | Properties object to customize the login prompt, without overriding the entire component (see below) | {} |
bypassProtection | Bypass protection for specific routes, decided by callback with NextRouter param | ({ route }) => false |
The loginComponentProps
object can contain any of the following options:
Option | Description | Default value |
---|---|---|
backUrl | Show a link with this URL to go back to main website | undefined |
buttonBackgroundColor | Login button background color | '#01EDBC' |
buttonColor | Login button color | '#111' |
logo | Show a logo above the prompt (img src) | undefined |
To change the default login component, a React component can be supplied to the withPasswordProtect
HOC. In order for the library to function properly, make sure your login component has password input that is validated by the the api route.
You can use src/hoc/LoginComponent.tsx
as a starting point.
AMP is not yet supported, because the LoginComponent failed AMP validation. On an AMP page, nothing is rendered. This could be fixed by changing LoginComponent to valid AMP.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 3/4 approved changesets -- score normalized to 7
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
Project has not signed or included provenance with any releases.
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
92 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More