Skip to content

Commit 31d2e8d

Browse files
committed
first commit
0 parents  commit 31d2e8d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+28867
-0
lines changed

.babelrc

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"presets": [
3+
"@babel/preset-env",
4+
"@babel/preset-typescript",
5+
"@babel/react"
6+
],
7+
"plugins": [
8+
"@babel/plugin-proposal-class-properties",
9+
"@babel/plugin-transform-runtime"
10+
]
11+
}

.commitlintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = { extends: ["@commitlint/config-conventional"] };

.cz-config.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
module.exports = {
2+
// add additional standard scopes here
3+
scopes: [{ name: "accounts" }, { name: "admin" }],
4+
// use this to permanently skip any questions by listing the message key as a string
5+
skipQuestions: [],
6+
7+
/* DEFAULT CONFIG */
8+
messages: {
9+
type: "What type of changes are you committing:",
10+
scope: "\nEnlighten us with the scope (optional):",
11+
customScope: "Add the scope of your liking:",
12+
subject: "Write a short and simple description of the change:\n",
13+
body:
14+
'Provide a LONGER description of the change (optional). Use "|" to break new line:\n',
15+
breaking: "List any BREAKING CHANGES (optional):\n",
16+
footer:
17+
"List any ISSUES CLOSED by this change (optional). E.g.: #31, #34:\n",
18+
confirmCommit: "Are you sure you the above looks right?",
19+
},
20+
types: [
21+
{
22+
value: "fix",
23+
name: "🐛 fix: Changes that fix a bug",
24+
emoji: "🐛",
25+
},
26+
{
27+
value: "feat",
28+
name: " 🚀 feat: Changes that introduce a new feature",
29+
emoji: "🚀",
30+
},
31+
{
32+
value: "refactor",
33+
name:
34+
"🔍 refactor: Changes that neither fixes a bug nor adds a feature",
35+
emoji: "🔍",
36+
},
37+
{
38+
value: "test",
39+
name: "💡 test: Adding missing tests",
40+
emoji: "💡",
41+
},
42+
{
43+
value: "style",
44+
name:
45+
"💅 style: Changes that do not impact the code base \n (white-space, formatting, missing semi-colons, etc)",
46+
emoji: "💅",
47+
},
48+
{
49+
value: "docs",
50+
name: "📝 docs: Changes to the docs",
51+
emoji: "📝",
52+
},
53+
{
54+
value: "chore",
55+
name:
56+
"🤖 chore: Changes to the build process or auxiliary tools\n and or libraries such as auto doc generation",
57+
emoji: "🤖",
58+
},
59+
],
60+
allowTicketNumber: false,
61+
isTicketNumberRequired: false,
62+
ticketNumberPrefix: "#",
63+
ticketNumberRegExp: "\\d{1,5}",
64+
allowCustomScopes: true,
65+
allowBreakingChanges: ["feat", "fix", "chore"],
66+
breakingPrefix: "🚧 BREAKING CHANGES 🚧",
67+
footerPrefix: "CLOSES ISSUE:",
68+
subjectLimit: 100,
69+
};

.eslintignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules/*
2+
node_modules
3+
public/*
4+
dist/
5+
.next
6+
.next/*

.github/workflows/release.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Release
2+
on:
3+
push:
4+
branches:
5+
- master
6+
jobs:
7+
release:
8+
name: Release
9+
runs-on: ubuntu-18.04
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v2
13+
with:
14+
fetch-depth: 0
15+
- name: Setup Node.js
16+
uses: actions/setup-node@v2
17+
with:
18+
node-version: 12
19+
- name: Install dependencies
20+
run: yarn
21+
- name: Release
22+
env:
23+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
25+
run: yarn semantic-release

.github/workflows/test.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: CI
2+
on: [pull_request]
3+
jobs:
4+
test:
5+
name: 'Test'
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Checkout repo
9+
uses: actions/checkout@v2
10+
- name: Setup Node.js
11+
uses: actions/setup-node@v2
12+
with:
13+
node-version: 12
14+
- name: Install modules
15+
run: yarn
16+
- name: Run tests
17+
run: yarn test

.gitignore

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
node_modules
5+
.pnp
6+
.pnp.js
7+
8+
# testing
9+
coverage
10+
11+
# production
12+
dist
13+
14+
# misc
15+
.DS_Store
16+
.env*
17+
18+
# debug
19+
npm-debug.log*
20+
yarn-debug.log*
21+
yarn-error.log*
22+
storybook-static

.prettierignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules/*
2+
public/*
3+
.next
4+
.next/*
5+
dist
6+
coverage

.releaserc.json

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"plugins": [
3+
[
4+
"@semantic-release/commit-analyzer",
5+
{
6+
"preset": "angular",
7+
"releaseRules": [
8+
{
9+
"release": "patch",
10+
"type": "chore"
11+
},
12+
{
13+
"release": "patch",
14+
"type": "refactor"
15+
},
16+
{
17+
"release": "patch",
18+
"type": "style"
19+
}
20+
]
21+
}
22+
],
23+
"@semantic-release/release-notes-generator",
24+
[
25+
"@semantic-release/changelog",
26+
{
27+
"changelogFile": "CHANGELOG.md"
28+
}
29+
],
30+
"@semantic-release/npm",
31+
[
32+
"@semantic-release/github",
33+
{
34+
"assets": ["CHANGELOG.md"]
35+
}
36+
]
37+
]
38+
}
39+

.vscode/settings.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
// These are all my auto-save configs
3+
"editor.formatOnSave": true,
4+
// turn it off for JS and JSX, we will do this via eslint
5+
"[javascript]": {
6+
"editor.formatOnSave": false
7+
},
8+
"[javascriptreact]": {
9+
"editor.formatOnSave": false
10+
},
11+
"[typescript]": {
12+
"editor.formatOnSave": false
13+
},
14+
"[typescriptreact]": {
15+
"editor.formatOnSave": false
16+
},
17+
// tell the ESLint plugin to run on save
18+
"editor.codeActionsOnSave": {
19+
"source.fixAll": true
20+
},
21+
// Optional BUT IMPORTANT: If you have the prettier extension enabled for other languages like CSS and HTML, turn it off for JS since we are doing it through Eslint already
22+
"prettier.disableLanguages": ["javascript", "javascriptreact", "typescript", "typescriptreact"]
23+
}

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Story of AMS
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<p align="center">
2+
<a href="https://storyofams.com/" target="_blank" align="center">
3+
<img src="https://storyofams.com/public/[email protected]" alt="Story of AMS" width="120">
4+
</a>
5+
<h1 align="center">@storyofams/next-password-protect</h1>
6+
</p>
7+
8+
Password protect your Next.js deployments.
9+
10+
## Installation
11+
12+
```sh
13+
yarn add @storyofams/next-password-protect
14+
# or
15+
npm install @storyofams/next-password-protect
16+
```
17+
18+
## Usage
19+
20+
There are 3 steps to enabling password protect: setting a global variable, adding the API route, and adding the HOC to \_app.
21+
22+
### Step 1
23+
24+
In order to be able to take advantage of dead code elimination, this library must be enabled using a global variable: `PASSWORD_PROTECT`.
25+
26+
To set this variable, add the following to `next.config.js`:
27+
28+
```javascript
29+
const webpack = require('webpack');
30+
31+
module.exports = {
32+
webpack(config) {
33+
config.plugins.push(
34+
new webpack.DefinePlugin({
35+
PASSWORD_PROTECT: JSON.stringify(
36+
// Add any logic you want here,
37+
// returning `true` to enable password protect.
38+
process.env.ENVIRONMENT === 'staging',
39+
),
40+
}),
41+
);
42+
43+
return config;
44+
},
45+
});
46+
```
47+
48+
### Step 2
49+
50+
Add an api route with the `passwordProtectHandler` api function. You can name it anything, as long as you pass the name to `apiPath` in the next step. By default it expects `/login`.
51+
52+
```javascript
53+
import { passwordProtectHandler } from "@storyofams/next-password-protect";
54+
55+
export default passwordProtectHandler({
56+
// Options go here (optional)
57+
cookieName: "authorization",
58+
});
59+
```
60+
61+
### Step 3
62+
63+
Add the `withPasswordProtect` HOC to the default export of `App` in `pages/_app.tsx`:
64+
65+
```javascript
66+
import { withPasswordProtect } from "@storyofams/next-password-protect";
67+
68+
// Before: export default App;
69+
export default withPasswordProtect(App, "password", {
70+
// Options go here (optional)
71+
apiPath: "/login",
72+
cookieName: "authorization",
73+
});
74+
```
75+
76+
_Note_: make sure to specify `apiPath` if the api route is not at `/login`!

example/.commitlintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = { extends: ["@commitlint/config-conventional"] };

0 commit comments

Comments
 (0)