├── .eslintignore
├── .eslintrc.json
├── .github
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ └── feature_request.md
└── workflows
│ ├── CI.js.yml
│ └── npm-publish.yml
├── .gitignore
├── .npmignore
├── .prettierignore
├── .prettierrc
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.MD
├── LICENSE
├── README.md
├── __tests__
└── unit
│ ├── getData.test.js
│ ├── login.test.js
│ ├── logout.test.js
│ └── verify.test.js
├── example
├── package-lock.json
├── package.json
├── public
│ ├── GentySans-Regular.woff
│ ├── GentySans-Regular.woff2
│ ├── bg.svg
│ ├── hero.png
│ ├── icon.png
│ └── index.html
├── src
│ ├── app.js
│ ├── components
│ │ ├── Input.js
│ │ ├── Input.module.css
│ │ ├── NavBar.js
│ │ └── NavBar.module.css
│ ├── context
│ │ ├── authContext.js
│ │ └── navContext.js
│ ├── global.css
│ ├── hooks
│ │ └── useInput.js
│ ├── index.js
│ └── pages
│ │ ├── Home.js
│ │ ├── Home.module.css
│ │ ├── Login.js
│ │ └── Login.module.css
└── webpack.config.js
├── index.js
├── lib
├── getData.js
├── login.js
├── logout.js
└── verify.js
├── package-lock.json
└── package.json
/.eslintignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | example/
--------------------------------------------------------------------------------
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "browser": true,
4 | "commonjs": true,
5 | "es2021": true
6 | },
7 | "extends": "eslint:recommended",
8 | "parserOptions": {
9 | "ecmaVersion": 12
10 | },
11 | "rules": {
12 | "indent": ["error", 4],
13 | "linebreak-style": "off",
14 | "quotes": ["error", "single"],
15 | "semi": ["error", "always"],
16 | "no-unused-vars": ["warn", { "args": "none" }]
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Steps to reproduce the behavior:
15 | 1. Go to '...'
16 | 2. Click on '....'
17 | 3. Scroll down to '....'
18 | 4. See error
19 |
20 | **Expected behavior**
21 | A clear and concise description of what you expected to happen.
22 |
23 | **Screenshots**
24 | If applicable, add screenshots to help explain your problem.
25 |
26 | **Desktop (please complete the following information):**
27 | - OS: [e.g. iOS]
28 | - Browser [e.g. chrome, safari]
29 | - Version [e.g. 22]
30 |
31 | **Smartphone (please complete the following information):**
32 | - Device: [e.g. iPhone6]
33 | - OS: [e.g. iOS8.1]
34 | - Browser [e.g. stock browser, safari]
35 | - Version [e.g. 22]
36 |
37 | **Additional context**
38 | Add any other context about the problem here.
39 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Describe alternatives you've considered**
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | **Additional context**
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/.github/workflows/CI.js.yml:
--------------------------------------------------------------------------------
1 | # This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3 |
4 | name: Node.js CI
5 |
6 | on:
7 | push:
8 | branches: [ main ]
9 | pull_request:
10 | branches: [ main ]
11 |
12 | jobs:
13 | build:
14 |
15 | runs-on: ubuntu-latest
16 |
17 | strategy:
18 | matrix:
19 | node-version: [14.x]
20 | # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
21 |
22 | steps:
23 | - uses: actions/checkout@v2
24 | - name: Use Node.js ${{ matrix.node-version }}
25 | uses: actions/setup-node@v2
26 | with:
27 | node-version: ${{ matrix.node-version }}
28 | cache: 'npm'
29 | - name: 'Install dependencies'
30 | run: npm ci
31 | - name: 'Run tests'
32 | run: npm test
33 | - name: 'Check linting'
34 | run: npm run lint
35 |
--------------------------------------------------------------------------------
/.github/workflows/npm-publish.yml:
--------------------------------------------------------------------------------
1 | # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
3 |
4 | name: AuthBee CI
5 |
6 | on:
7 | release:
8 | types: [created]
9 |
10 | jobs:
11 | build:
12 | runs-on: ubuntu-latest
13 | steps:
14 | - uses: actions/checkout@v2
15 | - uses: actions/setup-node@v2
16 | with:
17 | node-version: 16
18 | - run: npm i
19 | - run: npm test
20 |
21 | publish-npm:
22 | needs: build
23 | runs-on: ubuntu-latest
24 | steps:
25 | - uses: actions/checkout@v2
26 | - uses: actions/setup-node@v2
27 | with:
28 | node-version: 16
29 | registry-url: https://registry.npmjs.org/
30 | - run: npm i
31 | - run: npm publish
32 | env:
33 | NODE_AUTH_TOKEN: ${{secrets.npm_token}}
34 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | lerna-debug.log*
8 |
9 | # Diagnostic reports (https://nodejs.org/api/report.html)
10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11 |
12 | # Runtime data
13 | pids
14 | *.pid
15 | *.seed
16 | *.pid.lock
17 |
18 | # Directory for instrumented libs generated by jscoverage/JSCover
19 | lib-cov
20 |
21 | # Coverage directory used by tools like istanbul
22 | coverage
23 | *.lcov
24 |
25 | # nyc test coverage
26 | .nyc_output
27 |
28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29 | .grunt
30 |
31 | # Bower dependency directory (https://bower.io/)
32 | bower_components
33 |
34 | # node-waf configuration
35 | .lock-wscript
36 |
37 | # Compiled binary addons (https://nodejs.org/api/addons.html)
38 | example/dist
39 | build/Release
40 |
41 | # Dependency directories
42 | node_modules/
43 | jspm_packages/
44 |
45 | # TypeScript v1 declaration files
46 | typings/
47 |
48 | # TypeScript cache
49 | *.tsbuildinfo
50 |
51 | # Optional npm cache directory
52 | .npm
53 |
54 | # Optional eslint cache
55 | .eslintcache
56 |
57 | # Microbundle cache
58 | .rpt2_cache/
59 | .rts2_cache_cjs/
60 | .rts2_cache_es/
61 | .rts2_cache_umd/
62 |
63 | # Optional REPL history
64 | .node_repl_history
65 |
66 | # Output of 'npm pack'
67 | *.tgz
68 |
69 | # Yarn Integrity file
70 | .yarn-integrity
71 |
72 | # dotenv environment variables file
73 | .env
74 | .env.test
75 |
76 | # parcel-bundler cache (https://parceljs.org/)
77 | .cache
78 |
79 | # Next.js build output
80 | .next
81 |
82 | # Nuxt.js build / generate output
83 | .nuxt
84 | dist
85 |
86 | # Gatsby files
87 | .cache/
88 | # Comment in the public line in if your project uses Gatsby and *not* Next.js
89 | # https://nextjs.org/blog/next-9-1#public-directory-support
90 | # public
91 |
92 | # vuepress build output
93 | .vuepress/dist
94 |
95 | # Serverless directories
96 | .serverless/
97 |
98 | # FuseBox cache
99 | .fusebox/
100 |
101 | # DynamoDB Local files
102 | .dynamodb/
103 |
104 | # TernJS port file
105 | .tern-port
106 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | example
2 | .eslintignore
3 | .eslintrc.json
4 | .gitignore
5 | .prettierignore
6 | .prettierrc
7 | LICENSE
8 | README.md
9 | node_modules
10 | __tests__
11 | .github
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | example/node_modules/
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "singleQuote": true,
3 | "semi": true,
4 | "tabWidth": 4
5 | }
6 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to make participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6 |
7 | ## Our Standards
8 |
9 | Examples of behavior that contributes to creating a positive environment include:
10 |
11 | - Using welcoming and inclusive language
12 | - Being respectful of differing viewpoints and experiences
13 | - Gracefully accepting constructive criticism
14 | - Focusing on what is best for the community
15 | - Showing empathy towards other community members
16 |
17 | Examples of unacceptable behavior by participants include:
18 |
19 | - The use of sexualized language or imagery and unwelcome sexual attention or advances
20 | - Trolling, insulting/derogatory comments, and personal or political attacks
21 | - Public or private harassment
22 | - Publishing others' private information, such as a physical or electronic address, without explicit permission
23 | - Other conduct which could reasonably be considered inappropriate in a professional setting
24 |
25 | ## Our Responsibilities
26 |
27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28 |
29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30 |
31 | ## Scope
32 |
33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34 |
35 | ## Enforcement
36 |
37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [shakyaimanjith32@gmail.com](mailto:shakyaimanjith32@gmail.com). All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38 |
39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40 |
41 | ## Attribution
42 |
43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [https://contributor-covenant.org/version/1/4][version]
44 |
45 | [homepage]: https://contributor-covenant.org
46 | [version]: https://contributor-covenant.org/version/1/4/
47 |
--------------------------------------------------------------------------------
/CONTRIBUTING.MD:
--------------------------------------------------------------------------------
1 | # Contributing To Auth Bee
2 |
3 | Hi, first of all I'd like to thank you for contributing AuthBee. It's people like you who makes AuthBee like tools great tools for developers.
4 |
5 | Following these guidelines helps to communicate that you respect the time of the fellow developers managing and developing this project. In return, the also should hel you in addressing your issue, assessing changes, and helping to finalize your pull request.
6 |
7 | ## What are the ways you can contribute to AuthBee?
8 |
9 | There are many ways you can contrbute to thi project such as,
10 |
11 | - Improving Documentations
12 | - Bug triaging
13 | - Writing tutorials about Authbee
14 | - Feature requests, etc...
15 |
16 | ## Ground Rules
17 |
18 | - Ensure cross-platform compaitibility for every change you make.
19 | - Create issues for any major changes and enhancements that you wish to make. Discuss things transparently and get community feedback.
20 | - Keep feature versions as small as possible, preferably one new feature per version.
21 |
22 | ## Is this your first contribution?
23 |
24 | No problems. Everyone one was once a beginner. First you can start by checking issues with `good first issue` which are specifically kept for beginners. Also, we recommend you to refer this [article](https://app.egghead.io/playlists/how-to-contribute-to-an-open-source-project-on-github) before making your pull request.
25 |
26 | ## Getting started
27 |
28 | 1. If you havent installed, please install `Node.Js` and `git`
29 | 2. First make a fork of the repo and clone the forked repo into your machine.
30 | 3. Then install all the dependencies by running `npm install`
31 | 4. Next make your changes.
32 | 5. Run `npm run lint` & `npm run test` to check whether there's no any issue in linting or testing.
33 | 6. Next push changes in to your forked repo.
34 | 7. Then create a pull request to the main repo from you forked repo.
35 |
36 | ## How to report a bug?
37 |
38 | When reporting a bug we highly encourage you to use the provided template. Else, you can create a custom issue but we'll not consider it, if it does not has following points.
39 |
40 | - Expected behaviour
41 | - Your environment details (browser version, etc...)
42 | - Your node version
43 | - Steps to reproduce the behaviour
44 |
45 | ## How to suggest a feature?
46 |
47 | If you find yourself wishing for a feature that doesn't exist in AuthBee, you are probably not alone. There are bound to be others out there with similar needs. Many of the features that AuthBee has today have been added because our users saw the need. Open an issue on our issues list on GitHub which describes the feature you would like to see, why you need it, and how it should work.
48 |
49 | ## So that's it and Thank You again for your support in improving AuthBee 🐝
50 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | # AuthBee
6 |
7 | AuthBee is a NPM package to implement authentication in your JavaScript project. If you are using JWT in your project, this is the best option for you since this tracks expirationDate with the help of localStorage and logouts the usert if token is expired.
8 |
9 | ## Features
10 |
11 | - Token Verification
12 | - Automatic Logout when token expires
13 |
14 | ## Why you should use AuthBee?
15 |
16 | When I was a begineer I felt real difficult to implement client side authentication with lots of complex stuff such as automatic logout, etc... So, no matter whether you are a beginner, intermidiate or an expert. You can use AuthBee to implement client side authentication in you JavaScript application.
17 |
18 | ## How to install AuthBee?
19 |
20 | ```
21 | npm i authbee
22 | ```
23 |
24 | ## How to use AuthBee?
25 |
26 | Basicall there are four functions exported from the package and you can use it in any place of your application to retrieve, validate, login or logout user from your application. Check out the code snippets down below and also I recommend you to checkout the React [example](https://github.com/shakyapeiris/AuthBee/tree/main/example) developed using AuthBee.
27 |
28 | ### [1. Login](https://github.com/shakyapeiris/AuthBee/blob/main/lib/login.js)
29 |
30 | Login is a promise and you must take `async` or `then` approach to use it. Also, you must send an object as a parameter of the function which contains the **_expiresIn_** property and **_token_** property.
31 |
32 | ```javascript
33 | import { login } from 'authbee'
34 | ...
35 | const submiLoginData = async(e) => {
36 | try{
37 | const url = 'https://yourapi.com/login';
38 | const response = await fetch(url, {
39 | method: 'POST',
40 | body: JSON.stringify({
41 | email: 'user@abc.com',
42 | password: '123',
43 | }),
44 | headers: {
45 | 'Content-Type': 'application/json'
46 | }
47 | })
48 |
49 | // most of the time an object
50 | const data = await response.json();
51 |
52 | // expiresIn must be an integer
53 | await login({ token: data.token, expiresIn: data.expiresIn })
54 | }catch(console.log)
55 | }
56 | ```
57 |
58 | ### [2. Logout](https://github.com/shakyapeiris/AuthBee/blob/main/lib/logout.js)
59 |
60 | Logout is also a promise and since I use `async/await` in the previous example, I'll use `then` for this one. Also, there must be a token in the local storage aleady and if not the function will throw an error.
61 |
62 | ```javascript
63 | import { logout } from 'authbee'
64 | ...
65 | const logoutHandler = () => {
66 | logout()
67 | .then(() => {
68 | ...
69 | })
70 | .catch(console.log)
71 | }
72 | ```
73 |
74 | ### [3. Verify](https://github.com/shakyapeiris/AuthBee/blob/main/lib/verify.js)
75 |
76 | Verify is the main function of the package since it is the function responsible for token validation and automatic logout functionalities. Most suitable place to use this function is in app wide state like contextAPI, redux, etc...
77 |
78 | ```javascript
79 | import { verify } from 'authbee'
80 | ...
81 | const authContext = () => {
82 | // basically verify returns a boolean
83 | if (verify()){
84 | ...
85 | }
86 | else {
87 | ...
88 | }
89 | }
90 | ```
91 |
92 | ### [4. Get Data](https://github.com/shakyapeiris/AuthBee/blob/main/lib/getData.js)
93 |
94 | Using get data function, you can retrieve the data stored in local storage when you logged in to the system and this is useful if you want to get the token in order to use it as an authentication header when send a request to the backend.
95 |
96 | getData is also a promise and if the user is not logged in to the system (no token is stored in localStorage), it will send an error.
97 |
98 | ```javascript
99 | import { getData } from 'authbee'
100 | ...
101 | const fetchData = () => {
102 | getData()
103 | .then(({ token, expiresIn }) => {
104 | ...
105 | })
106 | .catch(console.log)
107 | }
108 | ```
109 |
110 | ## Future of AuthBee
111 |
112 | I'm planning to implement following features into AuthBee inorder to make it more efficient.
113 |
114 | - Add Type definitions
115 | - Make auth bee usable for Server Side Rendered applications
116 | - Etc...
117 |
118 | I highly appreciate you contribution in improving AuthBee. Please refer following resources if you are willing to contribute to AuthBee.
119 |
120 | - [Contribution Guidlines]()
121 | - [Code of Conduct]()
122 |
123 | ## How to get more help?
124 |
125 | - [Twitter](https://twitter.com/Shakya55007271)
126 | - [Email](shakyaimanjith32@gmail.com)
127 | - [Instagram](https://www.instagram.com/thep33ra/)
128 | - Discord: Shakya Peiris#9502
129 |
130 | ## Thank You 🐝!
131 |
--------------------------------------------------------------------------------
/__tests__/unit/getData.test.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @jest-environment jsdom
3 | */
4 | /*eslint-env jest*/
5 | const getData = require('../../lib/getData');
6 |
7 | let values = {};
8 | window.localStorage.setItem = jest.fn((key, value) => {
9 | values[key] = value;
10 | });
11 | window.localStorage.removeItem = jest.fn((key) => {
12 | values[key] = null;
13 | });
14 | window.localStorage.getItem = jest.fn((key) => values[key]);
15 |
16 | let dummyData = {
17 | token: '1234',
18 | expiresIn: 24,
19 | };
20 |
21 | describe('Unit tests of getData function', () => {
22 | test('Should send an error if not logged in', (done) => {
23 | expect.assertions(1);
24 | expect(getData()).rejects.toEqual('Must be logged in order to retrieve data');
25 | done();
26 | });
27 |
28 | test('Should send data if user is already logged in', (done) => {
29 | localStorage.setItem('token', dummyData.token);
30 | localStorage.setItem('expiresIn', dummyData.expiresIn);
31 | dummyData.expiresIn = dummyData.expiresIn.toString();
32 | getData().then((data) => {
33 | expect(data).toStrictEqual(dummyData);
34 | done();
35 | }).catch(done);
36 | });
37 | });
38 |
--------------------------------------------------------------------------------
/__tests__/unit/login.test.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @jest-environment jsdom
3 | */
4 | /*eslint-env jest*/
5 | const login = require('../../lib/login');
6 |
7 | let values = {};
8 | window.localStorage.setItem = jest.fn((key, value) => {
9 | values[key] = value;
10 | });
11 | window.localStorage.getItem = jest.fn((key) => values[key]);
12 |
13 | let dummyData = {
14 | token: '1234',
15 | expiresIn: 24,
16 | };
17 |
18 | describe('Unit tests of login module', () => {
19 | test('Should set data in local storage after logging', (done) => {
20 | login(dummyData)
21 | .then(() => {
22 | expect(
23 | localStorage.getItem('token')
24 | ).toBe(dummyData.token);
25 | done();
26 | })
27 | .catch(done);
28 | });
29 |
30 | test('Should send a error if token or expiresIn is missing', (done) => {
31 | expect.assertions(1);
32 | expect(login()).rejects.toEqual('Missing the token or expiresIn');
33 | done();
34 | });
35 |
36 | test('Should send an error when expiration date is not a number', (done) => {
37 | dummyData.expiresIn = 'someText';
38 | expect.assertions(1);
39 | expect(login(dummyData)).rejects.toEqual('Expiration date must be an integer');
40 | done();
41 | });
42 | });
43 |
--------------------------------------------------------------------------------
/__tests__/unit/logout.test.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @jest-environment jsdom
3 | */
4 | /*eslint-env jest*/
5 | const logout = require('../../lib/logout');
6 |
7 | let values = {};
8 | window.localStorage.setItem = jest.fn((key, value) => {
9 | values[key] = value;
10 | });
11 | window.localStorage.removeItem = jest.fn((key) => {
12 | values[key] = null;
13 | });
14 | window.localStorage.getItem = jest.fn((key) => values[key]);
15 |
16 | let dummyData = {
17 | token: '1234',
18 | expiresIn: 24,
19 | };
20 |
21 | describe('Unit tests of logout function', () => {
22 | beforeAll(() => {
23 | localStorage.setItem('token', dummyData.token);
24 | localStorage.setItem('expiresIn', dummyData.expiresIn);
25 | });
26 |
27 | test('Data should not be shown when logout function is called', (done) => {
28 | logout().then(() => {
29 | const token = localStorage.getItem('token');
30 | const expiresIn = localStorage.getItem('expiresIn');
31 | expect(token).toBeNull;
32 | expect(expiresIn).toBeNull;
33 | done();
34 | }).catch(done);
35 | });
36 |
37 | test('Should send an error if not logged in already', (done) => {
38 | localStorage.removeItem('token');
39 | expect.assertions(1);
40 | expect(logout()).rejects.toEqual('Must be logged in order to logout');
41 | done();
42 | });
43 |
44 | });
45 |
--------------------------------------------------------------------------------
/__tests__/unit/verify.test.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @jest-environment jsdom
3 | */
4 | /*eslint-env jest*/
5 | const verify = require('../../lib/verify');
6 |
7 | let values = {};
8 | window.localStorage.setItem = jest.fn((key, value) => {
9 | values[key] = value;
10 | });
11 | window.localStorage.removeItem = jest.fn((key) => {
12 | values[key] = null;
13 | });
14 | window.localStorage.getItem = jest.fn((key) => values[key]);
15 |
16 | let dummyData = {
17 | token: '1234',
18 | expiresIn: 24,
19 | };
20 |
21 | describe('Unit tests of verify function', () => {
22 | test('Should send false if expiration time is not set', (done) => {
23 | expect(verify()).toBe(false);
24 | done();
25 | });
26 |
27 | test('Should send true if expiration time is not reached', (done) => {
28 | const expirationDate = new Date().getTime() + dummyData.expiresIn * 3600000;
29 | localStorage.setItem('token', dummyData.token);
30 | localStorage.setItem('expiresIn', expirationDate);
31 |
32 | expect(verify()).toBe(true);
33 | done();
34 | });
35 |
36 | test('Should send false if expired', (done) => {
37 | const expirationDate = new Date().getTime() + dummyData.expiresIn * 3600000;
38 | localStorage.setItem('token', dummyData.token);
39 | localStorage.setItem('expiresIn', expirationDate);
40 |
41 | jest
42 | .useFakeTimers()
43 | .setSystemTime(expirationDate + 500);
44 |
45 | expect(verify()).toBe(false);
46 | done();
47 | });
48 | });
49 |
--------------------------------------------------------------------------------
/example/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "build": "rimraf dist && webpack",
8 | "start": "webpack serve",
9 | "test": "echo \"Error: no test specified\" && exit 1"
10 | },
11 | "keywords": [],
12 | "author": "",
13 | "license": "ISC",
14 | "dependencies": {
15 | "@tabler/icons": "^1.104.0",
16 | "authbee": "^1.0.2",
17 | "dotenv": "^10.0.0",
18 | "react": "^17.0.2",
19 | "react-dom": "^17.0.2"
20 | },
21 | "devDependencies": {
22 | "@babel/core": "^7.16.0",
23 | "@babel/preset-env": "^7.16.0",
24 | "@babel/preset-react": "^7.16.0",
25 | "babel-loader": "^8.2.3",
26 | "css-loader": "^6.5.0",
27 | "html-webpack-plugin": "^5.5.0",
28 | "rimraf": "^3.0.2",
29 | "style-loader": "^3.3.1",
30 | "webpack": "^5.61.0",
31 | "webpack-cli": "^4.9.1",
32 | "webpack-dev-server": "^4.11.1"
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/example/public/GentySans-Regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shakyapeiris/AuthBee/c675622418d8f5891189d6093a72b504630cdac2/example/public/GentySans-Regular.woff
--------------------------------------------------------------------------------
/example/public/GentySans-Regular.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shakyapeiris/AuthBee/c675622418d8f5891189d6093a72b504630cdac2/example/public/GentySans-Regular.woff2
--------------------------------------------------------------------------------
/example/public/bg.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/example/public/hero.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shakyapeiris/AuthBee/c675622418d8f5891189d6093a72b504630cdac2/example/public/hero.png
--------------------------------------------------------------------------------
/example/public/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shakyapeiris/AuthBee/c675622418d8f5891189d6093a72b504630cdac2/example/public/icon.png
--------------------------------------------------------------------------------
/example/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | AuthBee example
8 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/example/src/app.js:
--------------------------------------------------------------------------------
1 | import React, { useContext } from 'react';
2 | import NavBar from './components/NavBar';
3 | import Home from './pages/Home';
4 | import Login from './pages/Login';
5 | import { navContext } from './context/navContext';
6 |
7 | const app = () => {
8 | const navCtx = useContext(navContext);
9 | return (
10 | <>
11 |
12 | {navCtx.route === '/' ? (
13 |
14 | ) : navCtx.route === '/login' ? (
15 |
16 | ) : (
17 |