-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
51 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,48 @@ | ||
# TokenizedAuth | ||
# Tokenized auth | ||
|
||
<a alt="Nx logo" href="https://nx.dev" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-logo.png" width="45"></a> | ||
## Install | ||
|
||
✨ **This workspace has been generated by [Nx, Smart Monorepos · Fast CI.](https://nx.dev)** ✨ | ||
Run `npm i tokenized-auth` to install the library. | ||
|
||
## Integrate with editors | ||
## How to use | ||
|
||
Enhance your Nx experience by installing [Nx Console](https://nx.dev/nx-console) for your favorite editor. Nx Console | ||
provides an interactive UI to view your projects, run tasks, generate code, and more! Available for VSCode, IntelliJ and | ||
comes with a LSP for Vim users. | ||
|
||
## Build the library | ||
|
||
Run `npx nx build` to build the library. The build artifacts are stored in the output directory (i.e. `dist/`), ready to be published. | ||
|
||
## Running tasks | ||
|
||
To execute tasks with Nx use the following syntax: | ||
|
||
``` | ||
npx nx <target> <project> <...options> | ||
``` | ||
|
||
You can also run multiple targets: | ||
|
||
``` | ||
npx nx run-many -t <target1> <target2> | ||
``` | ||
|
||
..or add `-p` to filter specific projects | ||
### Generate key and encrypt it like a secret | ||
|
||
```typescript | ||
const key = await cryptoAuthUtils.encryptKey(); | ||
``` | ||
npx nx run-many -t <target1> <target2> -p <proj1> <proj2> | ||
Store generated key in the .env file | ||
|
||
Or you can generate this key then you build your application just create a file `generate-env.js` in the root of your project with the following content: | ||
|
||
```javascript | ||
const fs = require('fs'); | ||
const crypto = require('crypto').webcrypto; | ||
|
||
async function generateEncryptionKey() { | ||
const key = await crypto.subtle.generateKey( | ||
{ name: 'AES-GCM', length: 256 }, | ||
true, | ||
['encrypt', 'decrypt'] | ||
); | ||
const exportedKey = await crypto.subtle.exportKey('raw', key); | ||
const exportedKeyBuffer = Buffer.from(exportedKey); | ||
return exportedKeyBuffer.toString('base64'); | ||
} | ||
|
||
async function generateEnv() { | ||
const secretKey = await generateEncryptionKey(); | ||
const envContent = `\nENCRYPTION_KEY=${secretKey}\n`; | ||
fs.appendFileSync('.env', envContent); | ||
} | ||
|
||
generateEnv().then(); | ||
```` | ||
and update your `package.json` file: | ||
```json | ||
"scripts": { | ||
"build": "node generate-env.js && next build", | ||
// ... | ||
} | ||
``` | ||
|
||
Targets can be defined in the `package.json` or `projects.json`. Learn more [in the docs](https://nx.dev/features/run-tasks). | ||
|
||
## Set up CI! | ||
|
||
Nx comes with local caching already built-in (check your `nx.json`). On CI you might want to go a step further. | ||
|
||
- [Set up remote caching](https://nx.dev/features/share-your-cache) | ||
- [Set up task distribution across multiple machines](https://nx.dev/nx-cloud/features/distribute-task-execution) | ||
- [Learn more how to setup CI](https://nx.dev/recipes/ci) | ||
|
||
## Explore the project graph | ||
|
||
Run `npx nx graph` to show the graph of the workspace. | ||
It will show tasks that you can run with Nx. | ||
|
||
- [Learn more about Exploring the Project Graph](https://nx.dev/core-features/explore-graph) | ||
|
||
## Connect with us! | ||
|
||
- [Join the community](https://nx.dev/community) | ||
- [Subscribe to the Nx Youtube Channel](https://www.youtube.com/@nxdevtools) | ||
- [Follow us on Twitter](https://twitter.com/nxdevtools) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from './lib/tokenized-auth'; | ||
export { cryptoAuthUtils } from './lib/tokenized-auth'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters