Compare commits
82 Commits
@nhost/cor
...
@nhost/rea
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f58c2bb9ce | ||
|
|
41db6f613a | ||
|
|
ee84bfa098 | ||
|
|
ad1b7b80e2 | ||
|
|
3fcd345cff | ||
|
|
43a3f1dd46 | ||
|
|
3ec745c91e | ||
|
|
92deec4531 | ||
|
|
c7fcc9fe82 | ||
|
|
081377af6c | ||
|
|
23cb207afc | ||
|
|
0f55f6db9b | ||
|
|
7b16a8d790 | ||
|
|
dca8233601 | ||
|
|
a7535b260b | ||
|
|
82520963f1 | ||
|
|
722abd9a19 | ||
|
|
2aff6c0b4e | ||
|
|
e101915f60 | ||
|
|
0195143fe1 | ||
|
|
e362925041 | ||
|
|
b4f8c7457d | ||
|
|
84f1ab2f61 | ||
|
|
dee93bb873 | ||
|
|
173b587802 | ||
|
|
30ef1660b4 | ||
|
|
a613aa9f0c | ||
|
|
3c03b9b46f | ||
|
|
65a3061146 | ||
|
|
55864eac30 | ||
|
|
28494d6c1f | ||
|
|
34532b1a2f | ||
|
|
67f0450dac | ||
|
|
584976d1ad | ||
|
|
509ed7d864 | ||
|
|
71b92363b4 | ||
|
|
bb548cd108 | ||
|
|
adb30c537f | ||
|
|
d7d3e8f903 | ||
|
|
8a4064e99f | ||
|
|
937e28116b | ||
|
|
d885fe7b02 | ||
|
|
b0d7217276 | ||
|
|
bfba4ae7ec | ||
|
|
44b12dc0a0 | ||
|
|
bf6ee5d360 | ||
|
|
9f8bdb504d | ||
|
|
cd2594f66a | ||
|
|
c6a3e9f516 | ||
|
|
1bfb1e6d10 | ||
|
|
35fd7b1b7c | ||
|
|
04c1ed6955 | ||
|
|
0c591daef4 | ||
|
|
6f5729eb45 | ||
|
|
9bc447dbff | ||
|
|
d2d0e7fced | ||
|
|
0ad654226b | ||
|
|
9d8f2dea22 | ||
|
|
f3a44931a5 | ||
|
|
1c1656441b | ||
|
|
5f68f8fe31 | ||
|
|
961103d7a5 | ||
|
|
2bebab3f8e | ||
|
|
0363abbbb1 | ||
|
|
2f3715d02a | ||
|
|
7c101e5226 | ||
|
|
ef943995e2 | ||
|
|
b6032508bc | ||
|
|
a6b00294e7 | ||
|
|
dbfc5ec220 | ||
|
|
6ffaf31af5 | ||
|
|
8ec18157bb | ||
|
|
175ab26e04 | ||
|
|
eb2d064cbe | ||
|
|
17d2c8c3d9 | ||
|
|
4e0aab1bb2 | ||
|
|
1bde3e6516 | ||
|
|
3674f11183 | ||
|
|
76b3cb4643 | ||
|
|
556190dfc5 | ||
|
|
69f3a84bf5 | ||
|
|
16dcd314bb |
@@ -1,50 +0,0 @@
|
||||
{
|
||||
"env": {
|
||||
"browser": true,
|
||||
"es6": true,
|
||||
"node": true
|
||||
},
|
||||
"ignorePatterns": ["**/dist", "**/build", "**/.next"],
|
||||
"extends": ["react-app", "plugin:react/recommended", "plugin:react-hooks/recommended"],
|
||||
"parserOptions": {
|
||||
// "project": "./tsconfig.json"
|
||||
"project": ["packages/*/tsconfig.json", "examples/*/tsconfig.json"]
|
||||
},
|
||||
"plugins": ["react", "@typescript-eslint", "react-hooks", "simple-import-sort"],
|
||||
"rules": {
|
||||
"no-use-before-define": "off",
|
||||
"simple-import-sort/exports": "error",
|
||||
|
||||
"simple-import-sort/imports": [
|
||||
"error",
|
||||
{
|
||||
"groups": [
|
||||
// Node.js builtins. You could also generate this regex if you use a `.js` config.
|
||||
// For example: `^(${require("module").builtinModules.join("|")})(/|$)`
|
||||
[
|
||||
"^(assert|buffer|child_process|cluster|console|constants|crypto|dgram|dns|domain|events|fs|http|https|module|net|os|path|punycode|querystring|readline|repl|stream|string_decoder|sys|timers|tls|tty|url|util|vm|zlib|freelist|v8|process|async_hooks|http2|perf_hooks)(/.*|$)"
|
||||
],
|
||||
// Packages
|
||||
["^\\w"],
|
||||
// Internal packages.
|
||||
["^(@|config/)(/*|$)"],
|
||||
// Side effect imports.
|
||||
["^\\u0000"],
|
||||
// Parent imports. Put `..` last.
|
||||
["^\\.\\.(?!/?$)", "^\\.\\./?$"],
|
||||
// Other relative imports. Put same-folder imports and `.` last.
|
||||
["^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$"],
|
||||
// Style imports.
|
||||
["^.+\\.s?css$"]
|
||||
]
|
||||
}
|
||||
],
|
||||
"import/no-anonymous-default-export": [
|
||||
"error",
|
||||
{
|
||||
"allowArrowFunction": true,
|
||||
"allowAnonymousFunction": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
const esbuild = require('esbuild')
|
||||
|
||||
// Automatically exclude all node_modules from the bundled version
|
||||
const { nodeExternalsPlugin } = require('esbuild-node-externals')
|
||||
esbuild
|
||||
.build({
|
||||
entryPoints: ['./src/index.ts'],
|
||||
outfile: 'dist/index.cjs.js',
|
||||
bundle: true,
|
||||
minify: true,
|
||||
platform: 'node',
|
||||
format: 'cjs',
|
||||
sourcemap: true,
|
||||
target: 'node14',
|
||||
plugins: [nodeExternalsPlugin()]
|
||||
})
|
||||
.catch(() => process.exit(1))
|
||||
|
||||
esbuild
|
||||
.build({
|
||||
entryPoints: ['./src/index.ts'],
|
||||
outfile: 'dist/index.es.js',
|
||||
bundle: true,
|
||||
minify: true,
|
||||
platform: 'browser',
|
||||
format: 'esm',
|
||||
sourcemap: true,
|
||||
target: 'es2019'
|
||||
})
|
||||
.catch(() => process.exit(1))
|
||||
@@ -1,7 +0,0 @@
|
||||
const base = require('./jest.config.base.js')
|
||||
|
||||
module.exports = {
|
||||
...base,
|
||||
projects: ['<rootDir>/packages/*/jest.config.js'],
|
||||
coverageDirectory: '<rootDir>/coverage/'
|
||||
}
|
||||
10
.gitignore
vendored
10
.gitignore
vendored
@@ -19,6 +19,7 @@ logs/
|
||||
# Directories
|
||||
coverage/
|
||||
dist/
|
||||
umd/
|
||||
lib/
|
||||
node_modules/
|
||||
tmp/
|
||||
@@ -32,16 +33,15 @@ tmp/
|
||||
*.map
|
||||
todo.md
|
||||
|
||||
# Generated configs
|
||||
# Config files that are not part of the repository root anymore. Should be removed in the future.
|
||||
/.eslintignore
|
||||
/.eslintrc
|
||||
/.prettierignore
|
||||
/prettier.config.js
|
||||
/.eslintrc*
|
||||
/vite.*.js
|
||||
/jest.*.js
|
||||
/*tsconfig*.json
|
||||
/esbuild.*.js
|
||||
|
||||
!.config/**
|
||||
!config/**
|
||||
|
||||
*.tsbuildinfo
|
||||
|
||||
|
||||
@@ -11,6 +11,11 @@ module.exports = {
|
||||
tabWidth: 2,
|
||||
trailingComma: 'none',
|
||||
useTabs: false,
|
||||
// TODO: add import sort configuration to match ESLint rules
|
||||
// plugins: ['./node_modules/@trivago/prettier-plugin-sort-imports'],
|
||||
// importOrderSeparation: true,
|
||||
// importOrderSortSpecifiers: true
|
||||
plugins: [],
|
||||
overrides: [
|
||||
{
|
||||
files: ['*.json', '*.yaml'],
|
||||
@@ -18,7 +23,5 @@ module.exports = {
|
||||
useTabs: false
|
||||
}
|
||||
}
|
||||
],
|
||||
importOrderSeparation: true,
|
||||
importOrderSortSpecifiers: true
|
||||
]
|
||||
}
|
||||
@@ -2,15 +2,17 @@
|
||||
|
||||
## Requirements
|
||||
|
||||
- We use [pnpm](https://pnpm.io/) as a package manager to fasten development and builds, and as a backbone to our monorepo. You have to make sure it is installed in your machine. There are [multiple ways to install it](https://pnpm.io/installation), but the easiest way is with `npm`:
|
||||
- We use [pnpm](https://pnpm.io/) as a package manager to speed up development and builds, and as a basis for our monorepo. You need to make sure it's installed on your machine. There are [several ways to install it](https://pnpm.io/installation), but the easiest way is with `npm`:
|
||||
|
||||
```sh
|
||||
npm install -g pnpm
|
||||
$ npm install -g pnpm
|
||||
```
|
||||
|
||||
- Our tests and examples are using the Nhost CLI to run the backend services locally. You can follow the instructions to install it in [our documentation](https://docs.nhost.io/get-started/cli-workflow/install-cli)
|
||||
- Our tests and examples use the Nhost CLI, to run the backend services locally. You can follow the installation instructions in [our documentation](https://docs.nhost.io/get-started/cli-workflow/install-cli).
|
||||
|
||||
## Getting things ready
|
||||
## Get started
|
||||
|
||||
### Installation
|
||||
|
||||
First, clone this repository:
|
||||
|
||||
@@ -21,57 +23,74 @@ git clone https://github.com/nhost/nhost
|
||||
Then, install the dependencies with `pnpm`:
|
||||
|
||||
```sh
|
||||
cd nhost
|
||||
pnpm install
|
||||
$ cd nhost
|
||||
$ pnpm install
|
||||
```
|
||||
|
||||
## Starting development from an example
|
||||
### Development
|
||||
|
||||
Let's follow the instructions to start [react-apollo example](https://github.com/nhost/nhost/blob/main/examples/react-apollo/README.md).
|
||||
Although package references are correctly updated on the fly for TypeScript, example projects won't
|
||||
see the changes because they are depending on the build output. To fix this, you can run packages
|
||||
in development mode.
|
||||
|
||||
## Running the documentation website locally
|
||||
|
||||
The easier way to contribute to our documentation is to move to the `docs` folder and follow the [instructions to start local development](https://github.com/nhost/nhost/blob/main/docs/README.md):
|
||||
Running packages in development mode is as simple as:
|
||||
|
||||
```sh
|
||||
cd docs
|
||||
# not necessary step if you've done this step already anywhere in the repository
|
||||
pnpm install
|
||||
pnpm start
|
||||
$ pnpm dev
|
||||
```
|
||||
|
||||
## Testing
|
||||
Our packages are linked together using [PNPM's workspace](https://pnpm.io/workspaces) feature. Vite automatically detects changes in the dependencies and rebuilds everything, so that the changes are immediately reflected in the other packages.
|
||||
|
||||
In order to run tests, the Nhost testing backend should run locally. You can start it in from a separate terminal:
|
||||
### Use examples
|
||||
|
||||
Examples are a great way to test your changes in practice. Make sure you've `pnpm dev` running in your terminal and then run an example.
|
||||
|
||||
Let's follow the instructions to run [react-apollo example](https://github.com/nhost/nhost/blob/main/examples/react-apollo/README.md).
|
||||
|
||||
## Run the documentation website locally
|
||||
|
||||
The easier way to contribute to our documentation is to go to the `docs` folder and follow the [instructions to start local development](https://github.com/nhost/nhost/blob/main/docs/README.md):
|
||||
|
||||
```sh
|
||||
cd examples/testing-project
|
||||
nhost -d
|
||||
$ cd docs
|
||||
# not necessary if you've already done this step somewhere in the repository
|
||||
$ pnpm install
|
||||
$ pnpm start
|
||||
```
|
||||
|
||||
Once Nhost started locally, you can run the tests from the root folder of the repository with the following command:
|
||||
## Run test suites
|
||||
|
||||
In order to run tests, the Nhost testing backend should be running locally. You can run it from a separate terminal:
|
||||
|
||||
```sh
|
||||
pnpm test
|
||||
$ cd examples/testing-project
|
||||
$ nhost -d
|
||||
```
|
||||
|
||||
Once Nhost is started locally, you can run the tests with the following command from the repository root:
|
||||
|
||||
```sh
|
||||
$ pnpm test
|
||||
```
|
||||
|
||||
## Changesets
|
||||
|
||||
If you made some changes in the packages, you will have to describe these changes so they will be taken into account in the next release.
|
||||
We are using [changesets](https://github.com/changesets/changesets) to support our version/publish workflows. When submitting a pull request, a bot will check if some changesets are present, and if not, will guide you to add them.
|
||||
If you've made changes to the packages, you must describe those changes so that they can be reflected in the next release.
|
||||
We use [changesets](https://github.com/changesets/changesets) to support our versioning and release workflows. When you submit a pull request, a bot checks if some changesets are present, and if not, it directs you to add them.
|
||||
|
||||
The most comprehensive way to add a changeset is to run the following command from the root directory of the repository:
|
||||
The most comprehensive way to add a changeset is to run the following command in the repository root:
|
||||
|
||||
```sh
|
||||
pnpm changeset
|
||||
$ pnpm changeset
|
||||
```
|
||||
|
||||
This will generate a file in the `.changeset` directory. You can edit it to give further details about the change you just made.
|
||||
You can have a look at the changesets documentation on [how to add a changeset](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md)
|
||||
This will create a file in the `.changeset` directory. You can edit it to give more details about the change you just made.
|
||||
|
||||
## Commiting changes
|
||||
You can take a look at the changeset documentation: [How to add a changeset](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md).
|
||||
|
||||
You may notice `git commit` takes a few seconds to run. We set a commit hook that scan the changes in the code, automatically generates the documentation from the inline [TSDoc](https://tsdoc.org/) annotations, and add these generated documentation files to the commit. They will automatically update the [reference documentation](https://docs.nhost.io/reference).
|
||||
## Committing changes
|
||||
|
||||
You'll notice that `git commit` takes a few seconds to run. We set a commit hook that scans the changes in the code, automatically generates documentation from the inline [TSDoc](https://tsdoc.org/) annotations, and adds these generated documentation files to the commit. They automatically update the [reference documentation](https://docs.nhost.io/reference).
|
||||
|
||||
<!-- ## Good practices
|
||||
- lint
|
||||
|
||||
24
README.md
24
README.md
@@ -134,13 +134,6 @@ Here are some ways of contributing to making Nhost better:
|
||||
<sub><b>Pilou</b></sub>
|
||||
</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<a href="https://github.com/elitan">
|
||||
<img src="https://avatars.githubusercontent.com/u/331818?v=4" width="100;" alt="elitan"/>
|
||||
<br />
|
||||
<sub><b>Johan Eliasson</b></sub>
|
||||
</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<a href="https://github.com/szilarddoro">
|
||||
<img src="https://avatars.githubusercontent.com/u/310881?v=4" width="100;" alt="szilarddoro"/>
|
||||
@@ -148,6 +141,13 @@ Here are some ways of contributing to making Nhost better:
|
||||
<sub><b>Szilárd Dóró</b></sub>
|
||||
</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<a href="https://github.com/elitan">
|
||||
<img src="https://avatars.githubusercontent.com/u/331818?v=4" width="100;" alt="elitan"/>
|
||||
<br />
|
||||
<sub><b>Johan Eliasson</b></sub>
|
||||
</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<a href="https://github.com/nunopato">
|
||||
<img src="https://avatars.githubusercontent.com/u/1523504?v=4" width="100;" alt="nunopato"/>
|
||||
@@ -320,6 +320,13 @@ Here are some ways of contributing to making Nhost better:
|
||||
<sub><b>Jacob Duval</b></sub>
|
||||
</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<a href="https://github.com/MarcelloTheArcane">
|
||||
<img src="https://avatars.githubusercontent.com/u/21159570?v=4" width="100;" alt="MarcelloTheArcane"/>
|
||||
<br />
|
||||
<sub><b>Max Reynolds</b></sub>
|
||||
</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<a href="https://github.com/ghoshnirmalya">
|
||||
<img src="https://avatars.githubusercontent.com/u/6391763?v=4" width="100;" alt="ghoshnirmalya"/>
|
||||
@@ -333,7 +340,8 @@ Here are some ways of contributing to making Nhost better:
|
||||
<br />
|
||||
<sub><b>Quentin Decré</b></sub>
|
||||
</a>
|
||||
</td>
|
||||
</td></tr>
|
||||
<tr>
|
||||
<td align="center">
|
||||
<a href="https://github.com/komninoschat">
|
||||
<img src="https://avatars.githubusercontent.com/u/29049104?v=4" width="100;" alt="komninoschat"/>
|
||||
|
||||
65
config/.eslintrc.js
Normal file
65
config/.eslintrc.js
Normal file
@@ -0,0 +1,65 @@
|
||||
module.exports = {
|
||||
env: {
|
||||
browser: true,
|
||||
es6: true,
|
||||
node: true
|
||||
},
|
||||
ignorePatterns: [
|
||||
'dist',
|
||||
'umd',
|
||||
'build',
|
||||
'.next',
|
||||
'node_modules',
|
||||
'tsup.config.ts',
|
||||
'__tests__',
|
||||
'__mocks__',
|
||||
'*.test.ts',
|
||||
'*.test.tsx',
|
||||
'*.spec.ts',
|
||||
'*.spec.tsx',
|
||||
'tests/**/*.ts',
|
||||
'tests/**/*.d.ts'
|
||||
],
|
||||
extends: ['react-app', 'plugin:react/recommended', 'plugin:react-hooks/recommended'],
|
||||
parserOptions: {
|
||||
ecmaVersion: 2020,
|
||||
sourceType: 'module'
|
||||
},
|
||||
plugins: ['react', '@typescript-eslint', 'react-hooks', 'simple-import-sort'],
|
||||
rules: {
|
||||
'react/prop-types': 'off',
|
||||
'no-use-before-define': 'off',
|
||||
'simple-import-sort/exports': 'error',
|
||||
'simple-import-sort/imports': [
|
||||
'error',
|
||||
{
|
||||
groups: [
|
||||
// Node.js builtins. You could also generate this regex if you use a `.js` config.
|
||||
// For example: `^(${require("module").builtinModules.join("|")})(/|$)`
|
||||
[
|
||||
'^(assert|buffer|child_process|cluster|console|constants|crypto|dgram|dns|domain|events|fs|http|https|module|net|os|path|punycode|querystring|readline|repl|stream|string_decoder|sys|timers|tls|tty|url|util|vm|zlib|freelist|v8|process|async_hooks|http2|perf_hooks)(/.*|$)'
|
||||
],
|
||||
// Packages
|
||||
['^\\w'],
|
||||
// Internal packages.
|
||||
['^(@|config/)(/*|$)'],
|
||||
// Side effect imports.
|
||||
['^\\u0000'],
|
||||
// Parent imports. Put `..` last.
|
||||
['^\\.\\.(?!/?$)', '^\\.\\./?$'],
|
||||
// Other relative imports. Put same-folder imports and `.` last.
|
||||
['^\\./(?=.*/)(?!/?$)', '^\\.(?!/?$)', '^\\./?$'],
|
||||
// Style imports.
|
||||
['^.+\\.s?css$']
|
||||
]
|
||||
}
|
||||
],
|
||||
'import/no-anonymous-default-export': [
|
||||
'error',
|
||||
{
|
||||
allowArrowFunction: true,
|
||||
allowAnonymousFunction: true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ module.exports = {
|
||||
testRegex: '(/tests/.*.(test|spec)).(jsx?|tsx?)$',
|
||||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
|
||||
collectCoverage: true,
|
||||
// coveragePathIgnorePatterns: ['(tests/.*.mock).(jsx?|tsx?)$'],
|
||||
verbose: true,
|
||||
testTimeout: 30000,
|
||||
globals: {
|
||||
15
config/jest.config.js
Normal file
15
config/jest.config.js
Normal file
@@ -0,0 +1,15 @@
|
||||
module.exports = {
|
||||
rootDir: process.cwd(),
|
||||
preset: 'ts-jest',
|
||||
collectCoverage: true,
|
||||
coverageProvider: 'v8',
|
||||
coverageDirectory: '<rootDir>/coverage',
|
||||
clearMocks: true,
|
||||
verbose: true,
|
||||
testTimeout: 30000,
|
||||
globals: {
|
||||
'ts-jest': {
|
||||
isolatedModules: true
|
||||
}
|
||||
}
|
||||
}
|
||||
8
config/react-library.tsconfig.json
Normal file
8
config/react-library.tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"display": "React Library",
|
||||
"extends": "./tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"jsx": "preserve"
|
||||
}
|
||||
}
|
||||
56
config/tsconfig.base.json
Normal file
56
config/tsconfig.base.json
Normal file
@@ -0,0 +1,56 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"display": "Default",
|
||||
"compilerOptions": {
|
||||
"composite": false,
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"strict": true,
|
||||
"isolatedModules": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"skipLibCheck": true,
|
||||
"moduleResolution": "node",
|
||||
"target": "ES6",
|
||||
"module": "CommonJS",
|
||||
"lib": [
|
||||
"es5",
|
||||
"dom",
|
||||
"es2015.promise",
|
||||
"es2015.symbol",
|
||||
"es2015.iterable",
|
||||
"es2015.collection",
|
||||
"es2015.symbol.wellknown",
|
||||
"es2015.core",
|
||||
"es2017.object",
|
||||
"es2017.string"
|
||||
],
|
||||
"resolveJsonModule": true,
|
||||
"esModuleInterop": true,
|
||||
"sourceMap": true,
|
||||
"types": ["node"],
|
||||
"typeRoots": [
|
||||
"./node_modules/@types", "**/*/dist", "**/*/build", "**/*/.next", "**/*/umd"
|
||||
],
|
||||
"paths": {
|
||||
"@nhost/apollo": ["../packages/apollo/src/index.ts"],
|
||||
"@nhost/core": ["../packages/core/src/index.ts"],
|
||||
"@nhost/docgen": ["../packages/docgen/src/index.ts"],
|
||||
"@nhost/hasura-auth-js": ["../packages/hasura-auth-js/src/index.ts"],
|
||||
"@nhost/hasura-storage-js": ["../packages/hasura-storage-js/src/index.ts"],
|
||||
"@nhost/nextjs": ["../packages/nextjs/src/index.ts"],
|
||||
"@nhost/nhost-js": ["../packages/nhost-js/src/index.ts"],
|
||||
"@nhost/react": ["../packages/react/src/index.ts"],
|
||||
"@nhost/react-apollo": ["../packages/react-apollo/src/index.ts"],
|
||||
"@nhost/react-auth": ["../packages/react-auth/src/index.ts"]
|
||||
}
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"**/*/dist",
|
||||
"**/*/build",
|
||||
"**/*/.next",
|
||||
"**/*/__tests__",
|
||||
"**/*/__mocks__"
|
||||
]
|
||||
}
|
||||
@@ -5,20 +5,19 @@ import { defineConfig } from 'vite'
|
||||
import dts from 'vite-plugin-dts'
|
||||
import tsconfigPaths from 'vite-tsconfig-paths'
|
||||
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
const PWD = process.env.PWD
|
||||
const pkg = require(path.join(PWD, 'package.json'))
|
||||
|
||||
const tsEntry = path.resolve(PWD, 'src/index.ts')
|
||||
const entry = fs.existsSync(tsEntry) ? tsEntry : tsEntry.replace('.ts', '.tsx')
|
||||
|
||||
/**
|
||||
* @type {import('vite').UserConfig}
|
||||
*/
|
||||
const deps = [...Object.keys(Object.assign({}, pkg.peerDependencies, pkg.dependencies))]
|
||||
|
||||
export default defineConfig({
|
||||
optimizeDeps: {
|
||||
include: ['react/jsx-runtime']
|
||||
},
|
||||
plugins: [
|
||||
react(),
|
||||
tsconfigPaths(),
|
||||
dts({
|
||||
exclude: ['**/*.spec.ts', '**/*.test.ts', '**/tests/**'],
|
||||
@@ -32,16 +31,29 @@ export default defineConfig({
|
||||
})
|
||||
],
|
||||
build: {
|
||||
sourcemap: true,
|
||||
lib: {
|
||||
entry,
|
||||
name: pkg.name,
|
||||
fileName: 'index'
|
||||
fileName: 'index',
|
||||
formats: ['cjs', 'es']
|
||||
},
|
||||
rollupOptions: {
|
||||
external: ['react', '@nhost/react'],
|
||||
external: (id) => deps.some((dep) => id.startsWith(dep)),
|
||||
output: {
|
||||
globals: {
|
||||
react: 'react',
|
||||
'graphql/language/printer': 'graphql/language/printer',
|
||||
'@apollo/client': '@apollo/client',
|
||||
'@apollo/client/link/context': '@apollo/client/link/context',
|
||||
'@apollo/client/link/subscriptions': '@apollo/client/link/subscriptions',
|
||||
'@apollo/client/utilities': '@apollo/client/utilities',
|
||||
'graphql-ws': 'graphql-ws',
|
||||
xstate: 'xstate',
|
||||
axios: 'axios',
|
||||
'js-cookie': 'Cookies',
|
||||
react: 'React',
|
||||
'react-dom': 'ReactDOM',
|
||||
'react/jsx-runtime': '_jsx',
|
||||
'@nhost/react': '@nhost/react'
|
||||
}
|
||||
}
|
||||
13
config/vite.lib.dev.config.js
Normal file
13
config/vite.lib.dev.config.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import { defineConfig } from 'vite'
|
||||
|
||||
import viteLibConfig from './vite.lib.config'
|
||||
|
||||
export default defineConfig({
|
||||
...viteLibConfig,
|
||||
build: {
|
||||
...viteLibConfig.build,
|
||||
watch: {
|
||||
buildDelay: 500
|
||||
}
|
||||
}
|
||||
})
|
||||
42
config/vite.lib.umd.config.js
Normal file
42
config/vite.lib.umd.config.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
import { defineConfig } from 'vite'
|
||||
import dts from 'vite-plugin-dts'
|
||||
import tsconfigPaths from 'vite-tsconfig-paths'
|
||||
|
||||
import baseLibConfig from './vite.lib.config'
|
||||
|
||||
const PWD = process.env.PWD
|
||||
const pkg = require(path.join(PWD, 'package.json'))
|
||||
|
||||
const deps = [...Object.keys(Object.assign({}, pkg.peerDependencies))]
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
tsconfigPaths(),
|
||||
dts({
|
||||
exclude: ['**/*.spec.ts', '**/*.test.ts', '**/tests/**'],
|
||||
afterBuild: () => {
|
||||
const types = fs.readdirSync(path.join(PWD, 'umd/src'))
|
||||
types.forEach((file) => {
|
||||
fs.renameSync(path.join(PWD, 'umd/src', file), path.join(PWD, 'umd', file))
|
||||
})
|
||||
fs.rmdirSync(path.join(PWD, 'umd/src'))
|
||||
}
|
||||
})
|
||||
],
|
||||
build: {
|
||||
...(baseLibConfig.build || {}),
|
||||
outDir: 'umd',
|
||||
lib: {
|
||||
...(baseLibConfig.build?.lib || {}),
|
||||
fileName: pkg.name.replace(/@nhost\//g, ''),
|
||||
formats: ['umd']
|
||||
},
|
||||
rollupOptions: {
|
||||
...(baseLibConfig.build?.rollupOptions || {}),
|
||||
external: (id) => deps.some((dep) => id.startsWith(dep))
|
||||
}
|
||||
}
|
||||
})
|
||||
8
config/vite.react.config.js
Normal file
8
config/vite.react.config.js
Normal file
@@ -0,0 +1,8 @@
|
||||
import react from '@vitejs/plugin-react'
|
||||
import { defineConfig } from 'vite'
|
||||
import baseLibConfig from './vite.lib.config'
|
||||
|
||||
export default defineConfig({
|
||||
...baseLibConfig,
|
||||
plugins: [react(), ...baseLibConfig.plugins]
|
||||
})
|
||||
12
config/vite.react.dev.config.js
Normal file
12
config/vite.react.dev.config.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import viteReactConfig from './vite.react.config'
|
||||
|
||||
export default defineConfig({
|
||||
...viteReactConfig,
|
||||
build: {
|
||||
...viteReactConfig.build,
|
||||
watch: {
|
||||
buildDelay: 500
|
||||
}
|
||||
}
|
||||
})
|
||||
45
config/vite.react.umd.config.js
Normal file
45
config/vite.react.umd.config.js
Normal file
@@ -0,0 +1,45 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
import { defineConfig } from 'vite'
|
||||
import dts from 'vite-plugin-dts'
|
||||
import tsconfigPaths from 'vite-tsconfig-paths'
|
||||
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
import baseLibConfig from './vite.lib.config'
|
||||
|
||||
const PWD = process.env.PWD
|
||||
const pkg = require(path.join(PWD, 'package.json'))
|
||||
|
||||
const deps = [...Object.keys(Object.assign({}, pkg.peerDependencies))]
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
react(),
|
||||
tsconfigPaths(),
|
||||
dts({
|
||||
exclude: ['**/*.spec.ts', '**/*.test.ts', '**/tests/**'],
|
||||
afterBuild: () => {
|
||||
const types = fs.readdirSync(path.join(PWD, 'umd/src'))
|
||||
types.forEach((file) => {
|
||||
fs.renameSync(path.join(PWD, 'umd/src', file), path.join(PWD, 'umd', file))
|
||||
})
|
||||
fs.rmdirSync(path.join(PWD, 'umd/src'))
|
||||
}
|
||||
})
|
||||
],
|
||||
build: {
|
||||
...(baseLibConfig.build || {}),
|
||||
outDir: 'umd',
|
||||
lib: {
|
||||
...(baseLibConfig.build?.lib || {}),
|
||||
fileName: pkg.name.replace(/@nhost\//g, ''),
|
||||
formats: ['umd']
|
||||
},
|
||||
rollupOptions: {
|
||||
...(baseLibConfig.build?.rollupOptions || {}),
|
||||
external: (id) => deps.some((dep) => id.startsWith(dep))
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"singleQuote": true,
|
||||
"printWidth": 80,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"trailingComma": "all",
|
||||
"bracketSpacing": true,
|
||||
"bracketSameLine": false,
|
||||
"endOfLine": "auto",
|
||||
"semi": true
|
||||
}
|
||||
9
docs/CHANGELOG.md
Normal file
9
docs/CHANGELOG.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# @nhost/docs
|
||||
|
||||
## 0.0.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 584976d: - publishable directory structure changes (ESM, CJS and UMD included in the output)
|
||||
- build system improvements
|
||||
- fixed some bundling concerns (https://github.com/nhost/nhost/issues/428)
|
||||
@@ -43,7 +43,7 @@ In your serverless function, you need to make sure the request actually comes fr
|
||||
- Check the header in the serverless function. It should match the environment variable `NHOST_WEBHOOK_SECRET`.
|
||||
|
||||
```js
|
||||
export default function async handler(req, res) {
|
||||
export default async function handler(req, res) {
|
||||
|
||||
// Check webhook secret to make sure the request is valid
|
||||
if (
|
||||
|
||||
@@ -12,7 +12,7 @@ custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-j
|
||||
Use `signUp` to sign up users using email an password.
|
||||
|
||||
```ts
|
||||
auth.signIn({ email, password }) // email password
|
||||
auth.signUp({ email, password }) // email password
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
@@ -4,7 +4,7 @@ title: signIn()
|
||||
sidebar_label: signIn()
|
||||
slug: /reference/javascript/auth/sign-in
|
||||
description: Use `signIn` to sign in users using email and password, passwordless (email or sms) or an external provider. `signIn` can be used in various ways depending on the parameters.
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L166
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L171
|
||||
---
|
||||
|
||||
# `signIn()`
|
||||
|
||||
@@ -4,7 +4,7 @@ title: signOut()
|
||||
sidebar_label: signOut()
|
||||
slug: /reference/javascript/auth/sign-out
|
||||
description: Use `signOut` to sign out a user
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L315
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L343
|
||||
---
|
||||
|
||||
# `signOut()`
|
||||
|
||||
@@ -4,7 +4,7 @@ title: resetPassword()
|
||||
sidebar_label: resetPassword()
|
||||
slug: /reference/javascript/auth/reset-password
|
||||
description: Use `resetPassword` to reset a user's password.
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L342
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L370
|
||||
---
|
||||
|
||||
# `resetPassword()`
|
||||
|
||||
@@ -4,7 +4,7 @@ title: changePassword()
|
||||
sidebar_label: changePassword()
|
||||
slug: /reference/javascript/auth/change-password
|
||||
description: Use `changePassword` to change a user's password.
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L367
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L395
|
||||
---
|
||||
|
||||
# `changePassword()`
|
||||
|
||||
@@ -4,7 +4,7 @@ title: sendVerificationEmail()
|
||||
sidebar_label: sendVerificationEmail()
|
||||
slug: /reference/javascript/auth/send-verification-email
|
||||
description: Use `sendVerificationEmail` to send a verification email to the specified email.
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L393
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L421
|
||||
---
|
||||
|
||||
# `sendVerificationEmail()`
|
||||
|
||||
@@ -4,7 +4,7 @@ title: changeEmail()
|
||||
sidebar_label: changeEmail()
|
||||
slug: /reference/javascript/auth/change-email
|
||||
description: Use `changeEmail` to change a user's email
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L420
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L448
|
||||
---
|
||||
|
||||
# `changeEmail()`
|
||||
|
||||
@@ -4,7 +4,7 @@ title: deanonymize()
|
||||
sidebar_label: deanonymize()
|
||||
slug: /reference/javascript/auth/deanonymize
|
||||
description: Use `deanonymize` to deanonymize a user
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L445
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L473
|
||||
---
|
||||
|
||||
# `deanonymize()`
|
||||
|
||||
@@ -4,7 +4,7 @@ title: onTokenChanged()
|
||||
sidebar_label: onTokenChanged()
|
||||
slug: /reference/javascript/auth/on-token-changed
|
||||
description: Use `onTokenChanged` to add a custom function that will trigger whenever the access and refresh token is changed.
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L479
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L507
|
||||
---
|
||||
|
||||
# `onTokenChanged()`
|
||||
|
||||
@@ -4,7 +4,7 @@ title: onAuthStateChanged()
|
||||
sidebar_label: onAuthStateChanged()
|
||||
slug: /reference/javascript/auth/on-auth-state-changed
|
||||
description: Use `onAuthStateChanged` to add a custom function that will trigger whenever the state of the user changed. Ex from signed in to signed out or vice versa.
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L516
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L544
|
||||
---
|
||||
|
||||
# `onAuthStateChanged()`
|
||||
|
||||
@@ -4,7 +4,7 @@ title: isAuthenticated()
|
||||
sidebar_label: isAuthenticated()
|
||||
slug: /reference/javascript/auth/is-authenticated
|
||||
description: Use `isAuthenticated` to check if the user is authenticated or not.
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L556
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L584
|
||||
---
|
||||
|
||||
# `isAuthenticated()`
|
||||
@@ -12,9 +12,9 @@ custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-j
|
||||
Use `isAuthenticated` to check if the user is authenticated or not.
|
||||
|
||||
```ts
|
||||
const = auth.isAuthenticated();
|
||||
const isAuthenticated = auth.isAuthenticated()
|
||||
|
||||
if (authenticated) {
|
||||
console.log('User is authenticated');
|
||||
if (isAuthenticated) {
|
||||
console.log('User is authenticated')
|
||||
}
|
||||
```
|
||||
|
||||
@@ -4,7 +4,7 @@ title: isAuthenticatedAsync()
|
||||
sidebar_label: isAuthenticatedAsync()
|
||||
slug: /reference/javascript/auth/is-authenticated-async
|
||||
description: Use `isAuthenticatedAsync` to wait and check if the user is authenticated or not.
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L574
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L602
|
||||
---
|
||||
|
||||
# `isAuthenticatedAsync()`
|
||||
@@ -12,9 +12,9 @@ custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-j
|
||||
Use `isAuthenticatedAsync` to wait and check if the user is authenticated or not.
|
||||
|
||||
```ts
|
||||
const isAuthenticated = awiat auth.isAuthenticatedAsync();
|
||||
const isAuthenticated = await auth.isAuthenticatedAsync()
|
||||
|
||||
if (isAuthenticated) {
|
||||
console.log('User is authenticated');
|
||||
console.log('User is authenticated')
|
||||
}
|
||||
```
|
||||
|
||||
@@ -4,7 +4,7 @@ title: getAuthenticationStatus()
|
||||
sidebar_label: getAuthenticationStatus()
|
||||
slug: /reference/javascript/auth/get-authentication-status
|
||||
description: Use `getAuthenticationStatus` to get the authentication status of the user.
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L601
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L629
|
||||
---
|
||||
|
||||
# `getAuthenticationStatus()`
|
||||
|
||||
@@ -5,7 +5,7 @@ sidebar_label: getJWTToken()
|
||||
slug: /reference/javascript/auth/get-jwt-token
|
||||
sidebar_class_name: deprecated
|
||||
description: No description provided.
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L615
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L643
|
||||
---
|
||||
|
||||
# `getJWTToken()`
|
||||
|
||||
@@ -4,7 +4,7 @@ title: getAccessToken()
|
||||
sidebar_label: getAccessToken()
|
||||
slug: /reference/javascript/auth/get-access-token
|
||||
description: Use `getAccessToken` to get the logged in user's access token.
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L629
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L657
|
||||
---
|
||||
|
||||
# `getAccessToken()`
|
||||
|
||||
@@ -4,7 +4,7 @@ title: getDecodedAccessToken()
|
||||
sidebar_label: getDecodedAccessToken()
|
||||
slug: /reference/javascript/auth/get-decoded-access-token
|
||||
description: Decode the current decoded access token (JWT), or return `null` if the user is not authenticated (no token)
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L637
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L665
|
||||
---
|
||||
|
||||
# `getDecodedAccessToken()`
|
||||
|
||||
@@ -4,7 +4,7 @@ title: getHasuraClaims()
|
||||
sidebar_label: getHasuraClaims()
|
||||
slug: /reference/javascript/auth/get-hasura-claims
|
||||
description: Decode the Hasura claims from the current access token (JWT) located in the `https://hasura.io/jwt/claims` namespace, or return `null` if the user is not authenticated (no token)
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L647
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L675
|
||||
---
|
||||
|
||||
# `getHasuraClaims()`
|
||||
|
||||
@@ -4,7 +4,7 @@ title: getHasuraClaim()
|
||||
sidebar_label: getHasuraClaim()
|
||||
slug: /reference/javascript/auth/get-hasura-claim
|
||||
description: Get the value of a given Hasura claim in the current access token (JWT). Returns null if the user is not authenticated, or if the claim is not in the token. Return `null` if the user is not authenticated (no token)
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L657
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L685
|
||||
---
|
||||
|
||||
# `getHasuraClaim()`
|
||||
|
||||
@@ -4,7 +4,7 @@ title: refreshSession()
|
||||
sidebar_label: refreshSession()
|
||||
slug: /reference/javascript/auth/refresh-session
|
||||
description: Use `refreshSession()` to refresh the current session or refresh the session with an provided `refreshToken`.
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L676
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L704
|
||||
---
|
||||
|
||||
# `refreshSession()`
|
||||
|
||||
@@ -4,7 +4,7 @@ title: getSession()
|
||||
sidebar_label: getSession()
|
||||
slug: /reference/javascript/auth/get-session
|
||||
description: Use `getSession()` to get the current session.
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L719
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L747
|
||||
---
|
||||
|
||||
# `getSession()`
|
||||
|
||||
@@ -4,7 +4,7 @@ title: getUser()
|
||||
sidebar_label: getUser()
|
||||
slug: /reference/javascript/auth/get-user
|
||||
description: Use `getUser()` to get the current user.
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L734
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L762
|
||||
---
|
||||
|
||||
# `getUser()`
|
||||
|
||||
@@ -4,7 +4,7 @@ title: NhostClient
|
||||
sidebar_label: NhostClient
|
||||
description: No description provided.
|
||||
slug: /reference/nextjs/nhost-client
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/nextjs/src/index.ts#L16
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/nextjs/src/index.ts#L17
|
||||
---
|
||||
|
||||
# `NhostClient`
|
||||
|
||||
@@ -4,7 +4,7 @@ title: useProviderLink()
|
||||
sidebar_label: useProviderLink()
|
||||
slug: /reference/nextjs/use-provider-link
|
||||
description: Hook that returns OAuth provider URLs
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/hooks/authentication.ts#L393
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/hooks/authentication.ts#L450
|
||||
---
|
||||
|
||||
# `useProviderLink()`
|
||||
|
||||
@@ -4,7 +4,7 @@ title: useSignInAnonymous()
|
||||
sidebar_label: useSignInAnonymous()
|
||||
slug: /reference/nextjs/use-sign-in-anonymous
|
||||
description: No description provided.
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/hooks/authentication.ts#L346
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/hooks/authentication.ts#L370
|
||||
---
|
||||
|
||||
# `useSignInAnonymous()`
|
||||
|
||||
@@ -4,7 +4,7 @@ title: useSignInEmailPassword()
|
||||
sidebar_label: useSignInEmailPassword()
|
||||
slug: /reference/nextjs/use-sign-in-email-password
|
||||
description: Email and Password Sign-In
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/hooks/authentication.ts#L114
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/hooks/authentication.ts#L116
|
||||
---
|
||||
|
||||
# `useSignInEmailPassword()`
|
||||
|
||||
@@ -4,7 +4,7 @@ title: useSignInEmailPasswordless()
|
||||
sidebar_label: useSignInEmailPasswordless()
|
||||
slug: /reference/nextjs/use-sign-in-email-passwordless
|
||||
description: Passwordless email authentication hook
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/hooks/authentication.ts#L284
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/hooks/authentication.ts#L292
|
||||
---
|
||||
|
||||
# `useSignInEmailPasswordless()`
|
||||
|
||||
@@ -4,7 +4,7 @@ title: NhostNextClientConstructorParams
|
||||
sidebar_label: NhostNextClientConstructorParams
|
||||
description: No description provided.
|
||||
displayed_sidebar: referenceSidebar
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/nextjs/src/index.ts#L10
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/nextjs/src/index.ts#L11
|
||||
---
|
||||
|
||||
# `NhostNextClientConstructorParams`
|
||||
|
||||
@@ -17,6 +17,13 @@ custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/pro
|
||||
|
||||
---
|
||||
|
||||
**<span className="parameter-name">initial</span>** <span className="optional-status">optional</span> `NhostSession`
|
||||
**<span className="parameter-name">initial</span>** <span className="optional-status">optional</span> [`NhostSession`](/reference/docgen/nextjs/types/nhost-session)
|
||||
|
||||
| Property | Type | Required | Notes |
|
||||
| :------------------------------------------------------------------------------------------------------- | :------- | :------: | :---- |
|
||||
| <span className="parameter-name"><span className="light-grey">initial.</span>user</span> | `User` | ✔️ | |
|
||||
| <span className="parameter-name"><span className="light-grey">initial.</span>refreshToken</span> | `string` | ✔️ | |
|
||||
| <span className="parameter-name"><span className="light-grey">initial.</span>accessTokenExpiresIn</span> | `number` | ✔️ | |
|
||||
| <span className="parameter-name"><span className="light-grey">initial.</span>accessToken</span> | `string` | ✔️ | |
|
||||
|
||||
---
|
||||
|
||||
30
docs/docs/reference/docgen/nextjs/types/nhost-session.mdx
Normal file
30
docs/docs/reference/docgen/nextjs/types/nhost-session.mdx
Normal file
@@ -0,0 +1,30 @@
|
||||
---
|
||||
# ⚠️ AUTO-GENERATED CONTENT. DO NOT EDIT THIS FILE DIRECTLY! ⚠️
|
||||
title: NhostSession
|
||||
sidebar_label: NhostSession
|
||||
description: No description provided.
|
||||
displayed_sidebar: referenceSidebar
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/core/src/types.ts#L126
|
||||
---
|
||||
|
||||
# `NhostSession`
|
||||
|
||||
## Parameters
|
||||
|
||||
---
|
||||
|
||||
**<span className="parameter-name">accessToken</span>** <span className="optional-status">required</span> `string`
|
||||
|
||||
---
|
||||
|
||||
**<span className="parameter-name">accessTokenExpiresIn</span>** <span className="optional-status">required</span> `number`
|
||||
|
||||
---
|
||||
|
||||
**<span className="parameter-name">refreshToken</span>** <span className="optional-status">required</span> `string`
|
||||
|
||||
---
|
||||
|
||||
**<span className="parameter-name">user</span>** <span className="optional-status">required</span> `User`
|
||||
|
||||
---
|
||||
@@ -4,7 +4,7 @@ title: useProviderLink()
|
||||
sidebar_label: useProviderLink()
|
||||
slug: /reference/react/use-provider-link
|
||||
description: Hook that returns OAuth provider URLs
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/hooks/authentication.ts#L393
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/hooks/authentication.ts#L450
|
||||
---
|
||||
|
||||
# `useProviderLink()`
|
||||
|
||||
@@ -4,7 +4,7 @@ title: useSignInAnonymous()
|
||||
sidebar_label: useSignInAnonymous()
|
||||
slug: /reference/react/use-sign-in-anonymous
|
||||
description: No description provided.
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/hooks/authentication.ts#L346
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/hooks/authentication.ts#L370
|
||||
---
|
||||
|
||||
# `useSignInAnonymous()`
|
||||
|
||||
@@ -4,7 +4,7 @@ title: useSignInEmailPassword()
|
||||
sidebar_label: useSignInEmailPassword()
|
||||
slug: /reference/react/use-sign-in-email-password
|
||||
description: Email and Password Sign-In
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/hooks/authentication.ts#L114
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/hooks/authentication.ts#L116
|
||||
---
|
||||
|
||||
# `useSignInEmailPassword()`
|
||||
|
||||
@@ -4,7 +4,7 @@ title: useSignInEmailPasswordless()
|
||||
sidebar_label: useSignInEmailPasswordless()
|
||||
slug: /reference/react/use-sign-in-email-passwordless
|
||||
description: Passwordless email authentication hook
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/hooks/authentication.ts#L284
|
||||
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/react/src/hooks/authentication.ts#L292
|
||||
---
|
||||
|
||||
# `useSignInEmailPasswordless()`
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@nhost/docs",
|
||||
"version": "0.0.0",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"docusaurus": "docusaurus",
|
||||
|
||||
10
examples/nextjs/.eslintrc.js
Normal file
10
examples/nextjs/.eslintrc.js
Normal file
@@ -0,0 +1,10 @@
|
||||
module.exports = {
|
||||
extends: [
|
||||
'../../config/.eslintrc.js',
|
||||
'plugin:react/jsx-runtime',
|
||||
'plugin:@next/next/recommended'
|
||||
],
|
||||
rules: {
|
||||
'react/react-in-jsx-scope': 'off'
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"extends": ["plugin:@next/next/recommended"],
|
||||
"rules": {
|
||||
"react/react-in-jsx-scope": "off",
|
||||
"react/prop-types": "off"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import Link from 'next/link'
|
||||
import React from 'react'
|
||||
|
||||
import { Button, ButtonVariant } from '@mantine/core'
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import React from 'react'
|
||||
import { FaFacebook, FaGithub, FaGoogle } from 'react-icons/fa'
|
||||
|
||||
import { useProviderLink } from '@nhost/react'
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { useRouter } from 'next/router'
|
||||
import { useState } from 'react'
|
||||
|
||||
import { Button, SimpleGrid, TextInput } from '@mantine/core'
|
||||
import { Button, Modal, SimpleGrid, TextInput } from '@mantine/core'
|
||||
import { showNotification } from '@mantine/notifications'
|
||||
import { useSignInEmailPasswordless } from '@nhost/nextjs'
|
||||
|
||||
export const SignUpPasswordlessForm: React.FC = () => {
|
||||
const router = useRouter()
|
||||
const { signInEmailPasswordless } = useSignInEmailPasswordless()
|
||||
const { signInEmailPasswordless } = useSignInEmailPasswordless({ redirectTo: '/guarded-ssr' })
|
||||
const [emailVerificationToggle, setEmailVerificationToggle] = useState(false)
|
||||
|
||||
const [email, setEmail] = useState('')
|
||||
const signIn = async () => {
|
||||
const result = await signInEmailPasswordless(email)
|
||||
@@ -18,11 +18,23 @@ export const SignUpPasswordlessForm: React.FC = () => {
|
||||
message: result.error.message
|
||||
})
|
||||
} else {
|
||||
router.replace('/')
|
||||
setEmailVerificationToggle(true)
|
||||
}
|
||||
}
|
||||
return (
|
||||
<SimpleGrid cols={1} spacing={6}>
|
||||
<Modal
|
||||
title="Verification email sent"
|
||||
centered
|
||||
opened={emailVerificationToggle}
|
||||
onClose={() => {
|
||||
setEmailVerificationToggle(false)
|
||||
}}
|
||||
>
|
||||
A verification email has been sent. Please check your inbox and follow the link to complete
|
||||
authentication. This page will automatically redirect you to the authenticated home page
|
||||
once the email has been verified.
|
||||
</Modal>
|
||||
<TextInput
|
||||
type="email"
|
||||
placeholder="Email Address"
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {}
|
||||
|
||||
const pkg = require('./package.json')
|
||||
// * Only required to make it work with the monorepo. Is not required otherwise
|
||||
const withTM = require('next-transpile-modules')(
|
||||
// * All references to workspace packages are transpiled
|
||||
Object.entries(pkg.dependencies)
|
||||
.filter(([name, version]) => version.startsWith('workspace'))
|
||||
.map(([name]) => name)
|
||||
)
|
||||
const withBundleAnalyzer = require('@next/bundle-analyzer')({
|
||||
enabled: process.env.ANALYZE === 'true'
|
||||
})
|
||||
|
||||
module.exports = withTM(nextConfig)
|
||||
module.exports = withBundleAnalyzer(nextConfig)
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"build": "ANALYZE=false next build",
|
||||
"build:analyze": "ANALYZE=true next build",
|
||||
"start": "next start",
|
||||
"prettier": "prettier --check .",
|
||||
"prettier:fix": "prettier --write .",
|
||||
@@ -19,12 +20,7 @@
|
||||
"@mantine/hooks": "^4.2.2",
|
||||
"@mantine/next": "^4.2.2",
|
||||
"@mantine/notifications": "^4.2.2",
|
||||
"@nhost/apollo": "workspace:*",
|
||||
"@nhost/core": "workspace:*",
|
||||
"@nhost/hasura-auth-js": "workspace:*",
|
||||
"@nhost/hasura-storage-js": "workspace:*",
|
||||
"@nhost/nextjs": "workspace:*",
|
||||
"@nhost/nhost-js": "workspace:*",
|
||||
"@nhost/react": "workspace:*",
|
||||
"@nhost/react-apollo": "workspace:*",
|
||||
"graphql": "^16.3.0",
|
||||
@@ -34,11 +30,11 @@
|
||||
"react-icons": "^4.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@next/bundle-analyzer": "^12.1.5",
|
||||
"@types/node": "17.0.23",
|
||||
"@types/react": "18.0.8",
|
||||
"@xstate/inspect": "^0.6.2",
|
||||
"eslint-config-next": "12.0.10",
|
||||
"next-transpile-modules": "^9.0.0",
|
||||
"typescript": "4.5.5",
|
||||
"ws": "^8.5.0",
|
||||
"xstate": "^4.31.0"
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { AppProps } from 'next/app'
|
||||
import Head from 'next/head'
|
||||
import React from 'react'
|
||||
|
||||
import { AppShell, Header, MantineProvider } from '@mantine/core'
|
||||
import { NotificationsProvider } from '@mantine/notifications'
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import Link from 'next/link'
|
||||
import React from 'react'
|
||||
|
||||
import { Container, Title } from '@mantine/core'
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import React from 'react'
|
||||
|
||||
import { Container, Title } from '@mantine/core'
|
||||
import { useAccessToken } from '@nhost/nextjs'
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { GetServerSideProps } from 'next'
|
||||
import React from 'react'
|
||||
|
||||
import { Container, Title } from '@mantine/core'
|
||||
import { NhostSession } from '@nhost/core'
|
||||
import { getNhostSession, useAccessToken } from '@nhost/nextjs'
|
||||
import { getNhostSession, NhostSession, useAccessToken } from '@nhost/nextjs'
|
||||
|
||||
import { authProtected } from '../components/protected-route'
|
||||
import { BACKEND_URL } from '../helpers'
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { NextPage } from 'next'
|
||||
import React from 'react'
|
||||
|
||||
import { Container, Title } from '@mantine/core'
|
||||
import { useAccessToken, useAuthenticated } from '@nhost/nextjs'
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { GetServerSideProps } from 'next'
|
||||
import React from 'react'
|
||||
|
||||
import { Container, Title } from '@mantine/core'
|
||||
import { NhostSession } from '@nhost/core'
|
||||
import { getNhostSession, useAccessToken, useAuthenticated } from '@nhost/nextjs'
|
||||
import { getNhostSession, NhostSession, useAccessToken, useAuthenticated } from '@nhost/nextjs'
|
||||
|
||||
import { BACKEND_URL } from '../helpers'
|
||||
|
||||
@@ -19,6 +17,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||
const PublicSSRPage: React.FC<{ initial: NhostSession }> = () => {
|
||||
const isAuthenticated = useAuthenticated()
|
||||
const accessToken = useAccessToken()
|
||||
|
||||
return (
|
||||
<Container>
|
||||
<Title>Public Server-side Page</Title>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { NextPage } from 'next'
|
||||
import React from 'react'
|
||||
import { FaLock } from 'react-icons/fa'
|
||||
|
||||
import { Divider } from '@mantine/core'
|
||||
|
||||
@@ -41,7 +41,6 @@ export const SignUpPasswordPage: NextPage = () => {
|
||||
transition="fade"
|
||||
centered
|
||||
transitionDuration={600}
|
||||
transitionTimingFunction="ease"
|
||||
opened={emailVerificationToggle}
|
||||
onClose={() => {
|
||||
setEmailVerificationToggle(false)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { NextPage } from 'next'
|
||||
import React from 'react'
|
||||
import { FaLock } from 'react-icons/fa'
|
||||
|
||||
import { Divider } from '@mantine/core'
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"extends": "../../config/tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
"@apollo/client": "^3.5.10",
|
||||
"@headlessui/react": "^1.5.0",
|
||||
"@heroicons/react": "^1.0.6",
|
||||
"@nhost/nhost-js": "workspace:*",
|
||||
"@nhost/react": "workspace:*",
|
||||
"@nhost/react-apollo": "workspace:*",
|
||||
"@tailwindcss/forms": "^0.5.0",
|
||||
@@ -61,11 +60,11 @@
|
||||
"@types/react": "^17.0.44",
|
||||
"@types/react-dom": "^17.0.15",
|
||||
"@types/express": "^4.17.13",
|
||||
"@vitejs/plugin-react": "^1.3.1",
|
||||
"@vitejs/plugin-react": "^1.3.2",
|
||||
"autoprefixer": "^10.4.4",
|
||||
"express": "^4.17.3",
|
||||
"postcss": "^8.4.12",
|
||||
"typescript": "^4.6.3",
|
||||
"vite": "^2.9.5"
|
||||
"vite": "^2.9.7"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,22 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"extends": "../../config/tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"composite": true,
|
||||
"module": "esnext"
|
||||
"target": "ESNext",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
||||
"allowJs": false,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": false,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx"
|
||||
},
|
||||
"include": ["src/**/*", "types/**/*", "../../types/**/*", "tests/**/*"]
|
||||
"include": ["src"],
|
||||
"references": [{ "path": "../../config/tsconfig.base.json" }]
|
||||
}
|
||||
|
||||
9
examples/react-apollo-crm/tsconfig.node.json
Normal file
9
examples/react-apollo-crm/tsconfig.node.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node"
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import tsconfigPaths from 'vite-tsconfig-paths'
|
||||
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [tsconfigPaths(), react()]
|
||||
optimizeDeps: {
|
||||
include: ['react/jsx-runtime']
|
||||
},
|
||||
plugins: [react()]
|
||||
})
|
||||
|
||||
@@ -16,7 +16,7 @@ auth:
|
||||
blocked_email_domains: ''
|
||||
blocked_emails: ''
|
||||
allowed_redirect_urls: ''
|
||||
anonymous_users_enabled: false
|
||||
anonymous_users_enabled: true
|
||||
client_url: http://localhost:3000
|
||||
disable_new_users: false
|
||||
email:
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
"@mantine/hooks": "^4.2.2",
|
||||
"@mantine/notifications": "^4.2.2",
|
||||
"@mantine/prism": "^4.2.2",
|
||||
"@nhost/core": "workspace:*",
|
||||
"@nhost/react": "workspace:*",
|
||||
"@nhost/react-apollo": "workspace:*",
|
||||
"graphql": "15.7.2",
|
||||
@@ -50,11 +49,10 @@
|
||||
"devDependencies": {
|
||||
"@types/react": "^18.0.8",
|
||||
"@types/react-dom": "^18.0.3",
|
||||
"@vitejs/plugin-react": "^1.3.1",
|
||||
"@vitejs/plugin-react": "^1.3.2",
|
||||
"@xstate/inspect": "^0.6.2",
|
||||
"typescript": "^4.6.3",
|
||||
"vite": "^2.9.5",
|
||||
"ws": "^8.6.0",
|
||||
"vite": "^2.9.7",
|
||||
"xstate": "^4.31.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { Container, Title } from '@mantine/core'
|
||||
import { useNhostClient } from '@nhost/react'
|
||||
import { useNhostClient, useSignInAnonymous } from '@nhost/react'
|
||||
import React from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
|
||||
export const AboutPage: React.FC = () => {
|
||||
const nhost = useNhostClient()
|
||||
const { signInAnonymous } = useSignInAnonymous()
|
||||
const fetch = async () => {
|
||||
const req = await nhost.graphql.request(`query BooksQuery {
|
||||
books {
|
||||
@@ -17,6 +18,14 @@ export const AboutPage: React.FC = () => {
|
||||
return (
|
||||
<Container>
|
||||
<Title>About this example</Title>
|
||||
<button
|
||||
onClick={async () => {
|
||||
const result = await signInAnonymous()
|
||||
console.log(result)
|
||||
}}
|
||||
>
|
||||
ANONYMOUS
|
||||
</button>
|
||||
<p>This application demonstrates the available features of the Nhost stack.</p>
|
||||
<button onClick={fetch}>Fetch</button>
|
||||
<div>
|
||||
|
||||
@@ -32,8 +32,8 @@ export const SignUpPasswordlessForm: React.FC = () => {
|
||||
}}
|
||||
>
|
||||
A verification email has been sent. Please check your inbox and follow the link to complete
|
||||
authentication. This page with automatically redirect to the authenticated home page once
|
||||
the email has been verified.
|
||||
authentication. This page will automatically redirect you to the authenticated home page
|
||||
once the email has been verified.
|
||||
</Modal>
|
||||
<TextInput
|
||||
type="email"
|
||||
|
||||
@@ -23,13 +23,14 @@ const container = document.getElementById('root')
|
||||
const root = createRoot(container!)
|
||||
root.render(
|
||||
// * See https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html#updates-to-strict-mode
|
||||
<React.StrictMode>
|
||||
<BrowserRouter>
|
||||
<NhostReactProvider nhost={nhost}>
|
||||
<NhostApolloProvider nhost={nhost}>
|
||||
<App />
|
||||
</NhostApolloProvider>
|
||||
</NhostReactProvider>
|
||||
</BrowserRouter>
|
||||
</React.StrictMode>
|
||||
// * The xstate inspector is hard to use with React 18 strict mode
|
||||
// <React.StrictMode>
|
||||
<BrowserRouter>
|
||||
<NhostReactProvider nhost={nhost}>
|
||||
<NhostApolloProvider nhost={nhost}>
|
||||
<App />
|
||||
</NhostApolloProvider>
|
||||
</NhostReactProvider>
|
||||
</BrowserRouter>
|
||||
// </React.StrictMode>
|
||||
)
|
||||
|
||||
@@ -1,9 +1,22 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"extends": "../../config/tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"composite": true,
|
||||
"module": "esnext"
|
||||
"target": "ESNext",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
||||
"allowJs": false,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": false,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx"
|
||||
},
|
||||
"include": ["src/**/*", "types/**/*", "../../types/**/*", "tests/**/*"]
|
||||
"include": ["src"],
|
||||
"references": [{ "path": "../../config/tsconfig.base.json" }]
|
||||
}
|
||||
|
||||
9
examples/react-apollo/tsconfig.node.json
Normal file
9
examples/react-apollo/tsconfig.node.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node"
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import tsconfigPaths from 'vite-tsconfig-paths'
|
||||
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [tsconfigPaths(), react()]
|
||||
optimizeDeps: {
|
||||
include: ['react/jsx-runtime']
|
||||
},
|
||||
plugins: [react()]
|
||||
})
|
||||
|
||||
24
package.json
24
package.json
@@ -15,26 +15,26 @@
|
||||
},
|
||||
"scripts": {
|
||||
"preinstall": "npx only-allow pnpm",
|
||||
"create-config": "cp -r .config/. ./",
|
||||
"prepare": "pnpm create-config && husky install",
|
||||
"build": "pnpm turbo run build --scope='@nhost/*' --no-deps --include-dependencies",
|
||||
"build:docs": "pnpm run build --filter=nhost-documentation",
|
||||
"prepare": "husky install",
|
||||
"build": "turbo run build --filter=!@nhost/docs --filter=!@nhost-examples/* --no-deps --include-dependencies",
|
||||
"build:docs": "pnpm run build --filter=@nhost/docs",
|
||||
"dev": "turbo run dev --filter=!@nhost/docs --filter=!@nhost-examples/* --filter=!@nhost/docgen --no-deps --include-dependencies",
|
||||
"clean:all": "pnpm clean && rm -rf ./{{packages,examples}/*,docs}/{.nhost,node_modules} node_modules",
|
||||
"clean": "rm -rf ./{{packages,examples}/*,docs}/{dist,.next,.turbo,coverage}",
|
||||
"ci": "pnpm turbo run build test --concurrency=4 --scope='@nhost/*' && pnpm run lint",
|
||||
"clean": "rm -rf ./{{packages,examples}/*,docs}/{dist,umd,.next,.turbo,coverage}",
|
||||
"ci": "turbo run build test --concurrency=4 --filter=!@nhost/docs --filter=!@nhost-examples/* && pnpm run lint",
|
||||
"ci:version": "changeset version && pnpm install --frozen-lockfile false",
|
||||
"coverage": "pnpm run test --coverage",
|
||||
"prettier": "prettier --check .",
|
||||
"prettier:fix": "prettier --write .",
|
||||
"lint": "pnpm turbo run lint --stream",
|
||||
"lint:fix": "pnpm turbo run lint:fix --stream",
|
||||
"lint": "turbo run lint --stream",
|
||||
"lint:fix": "turbo run lint:fix --stream",
|
||||
"prerelease": "pnpm clean && pnpm install && pnpm build",
|
||||
"release": "pnpm run prerelease && changeset publish",
|
||||
"snapshot": "pnpm prerelease && changeset version --snapshot preview && pnpm install && changeset publish --tag preview",
|
||||
"test": "pnpm turbo run test --scope='@nhost/*' --no-deps --include-dependencies",
|
||||
"test": "turbo run test --filter=!@nhost/docs --filter=!@nhost-examples/* --no-deps --include-dependencies",
|
||||
"changeset": "changeset",
|
||||
"wait": "wait-on http://localhost:1337/v1/auth/healthz -i 500 -t 120000",
|
||||
"docgen": "turbo run build --scope=\"@nhost/docgen\" --no-deps && turbo run docgen --scope='@nhost/*' && :"
|
||||
"docgen": "turbo run build --filter=@nhost/docgen --no-deps && turbo run docgen --filter='@nhost/*' && :"
|
||||
},
|
||||
"workspaces": [
|
||||
"packages/*",
|
||||
@@ -53,8 +53,6 @@
|
||||
"@typescript-eslint/eslint-plugin": "^5.22.0",
|
||||
"@typescript-eslint/parser": "^5.22.0",
|
||||
"@vitejs/plugin-react": "^1.3.2",
|
||||
"esbuild": "^0.14.38",
|
||||
"esbuild-node-externals": "^1.4.1",
|
||||
"eslint": "^8.14.0",
|
||||
"eslint-config-react-app": "^7.0.1",
|
||||
"eslint-plugin-flowtype": "^8.0.3",
|
||||
@@ -71,7 +69,7 @@
|
||||
"prettier": "^2.6.2",
|
||||
"ts-jest": "^27.1.4",
|
||||
"tsconfig-paths-jest": "^0.0.1",
|
||||
"turbo": "1.1.6",
|
||||
"turbo": "1.2.5",
|
||||
"typedoc": "^0.22.15",
|
||||
"typescript": "4.5.5",
|
||||
"vite": "^2.9.7",
|
||||
|
||||
7
packages/apollo/.eslintrc.js
Normal file
7
packages/apollo/.eslintrc.js
Normal file
@@ -0,0 +1,7 @@
|
||||
module.exports = {
|
||||
extends: '../../config/.eslintrc.js',
|
||||
parserOptions: {
|
||||
project: 'tsconfig.json',
|
||||
tsconfigRootDir: __dirname
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,22 @@
|
||||
# @nhost/apollo
|
||||
|
||||
## 0.5.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 584976d: - publishable directory structure changes (ESM, CJS and UMD included in the output)
|
||||
- build system improvements
|
||||
- fixed some bundling concerns (https://github.com/nhost/nhost/issues/428)
|
||||
- Updated dependencies [584976d]
|
||||
- @nhost/nhost-js@1.1.10
|
||||
|
||||
## 0.5.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [65a3061]
|
||||
- @nhost/core@0.5.2
|
||||
|
||||
## 0.5.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@nhost/apollo",
|
||||
"version": "0.5.1",
|
||||
"version": "0.5.3",
|
||||
"description": "Nhost Apollo Client library",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
@@ -21,11 +21,30 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/nhost/nhost.git"
|
||||
},
|
||||
"main": "dist/index.cjs.js",
|
||||
"module": "dist/index.es.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"source": "src/index.ts",
|
||||
"files": [
|
||||
"dist",
|
||||
"umd",
|
||||
"README.md"
|
||||
],
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/index.es.js",
|
||||
"require": "./dist/index.cjs.js"
|
||||
}
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "run-s build:esbuild build:types",
|
||||
"build:esbuild": "node ../../esbuild.lib.js",
|
||||
"build:types": "tsc --build tsconfig.types.json",
|
||||
"test": "pnpm jest --runInBand --config ../../jest.config.base.js",
|
||||
"dev": "vite build --config ../../config/vite.lib.dev.config.js",
|
||||
"build": "run-p build:lib build:umd",
|
||||
"build:lib": "vite build --config ../../config/vite.lib.config.js",
|
||||
"build:umd": "vite build --config ../../config/vite.lib.umd.config.js",
|
||||
"test": "pnpm jest --runInBand --config ../../config/jest.config.js",
|
||||
"prettier": "prettier --check src/",
|
||||
"prettier:fix": "prettier --write src/",
|
||||
"lint": "eslint . --ext .ts,.tsx",
|
||||
@@ -33,33 +52,15 @@
|
||||
"verify": "run-p prettier lint",
|
||||
"verify:fix": "run-p prettier:fix lint:fix"
|
||||
},
|
||||
"main": "src/index.ts",
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"main": "dist/index.cjs.js",
|
||||
"module": "dist/index.es.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/index.es.js",
|
||||
"require": "./dist/index.cjs.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"peerDependencies": {
|
||||
"@apollo/client": "^3.6.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nhost/core": "workspace:^",
|
||||
"@nhost/nhost-js": "workspace:*",
|
||||
"graphql": "16",
|
||||
"graphql-ws": "^5.7.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@apollo/client": "^3.6.2",
|
||||
"@nhost/nhost-js": "workspace:^",
|
||||
"xstate": "^4.31.0"
|
||||
"@apollo/client": "^3.6.2"
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,4 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"composite": true
|
||||
},
|
||||
"include": ["src/**/*", "types/**/*", "../../types/**/*", "tests/**/*"]
|
||||
}
|
||||
"extends": "../../config/tsconfig.base.json",
|
||||
"include": ["src"]
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"emitDeclarationOnly": true,
|
||||
"outDir": "dist",
|
||||
"rootDir": "src",
|
||||
"composite": false
|
||||
},
|
||||
"include": ["src/**/*"]
|
||||
}
|
||||
7
packages/core/.eslintrc.js
Normal file
7
packages/core/.eslintrc.js
Normal file
@@ -0,0 +1,7 @@
|
||||
module.exports = {
|
||||
extends: '../../config/.eslintrc.js',
|
||||
parserOptions: {
|
||||
project: 'tsconfig.json',
|
||||
tsconfigRootDir: __dirname
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,19 @@
|
||||
# @nhost/core
|
||||
|
||||
## 0.5.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 584976d: - publishable directory structure changes (ESM, CJS and UMD included in the output)
|
||||
- build system improvements
|
||||
- fixed some bundling concerns (https://github.com/nhost/nhost/issues/428)
|
||||
|
||||
## 0.5.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 65a3061: correct cookie storage type
|
||||
|
||||
## 0.5.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@nhost/core",
|
||||
"version": "0.5.1",
|
||||
"version": "0.5.3",
|
||||
"description": "Nhost core client library",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
@@ -20,11 +20,30 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/nhost/nhost.git"
|
||||
},
|
||||
"main": "dist/index.cjs.js",
|
||||
"module": "dist/index.es.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"source": "src/index.ts",
|
||||
"files": [
|
||||
"dist",
|
||||
"umd",
|
||||
"README.md"
|
||||
],
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/index.es.js",
|
||||
"require": "./dist/index.cjs.js"
|
||||
}
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "run-s build:esbuild build:types",
|
||||
"build:esbuild": "node ../../esbuild.lib.js",
|
||||
"build:types": "tsc --build tsconfig.types.json",
|
||||
"test": "pnpm jest --runInBand --config ../../jest.config.base.js",
|
||||
"dev": "vite build --config ../../config/vite.lib.dev.config.js",
|
||||
"build": "run-p build:lib build:umd",
|
||||
"build:lib": "vite build --config ../../config/vite.lib.config.js",
|
||||
"build:umd": "vite build --config ../../config/vite.lib.umd.config.js",
|
||||
"test": "pnpm jest --runInBand --config ../../config/jest.config.js",
|
||||
"prettier": "prettier --check src/",
|
||||
"prettier:fix": "prettier --write src/",
|
||||
"lint": "eslint . --ext .ts,.tsx",
|
||||
@@ -32,24 +51,8 @@
|
||||
"verify": "run-p prettier lint",
|
||||
"verify:fix": "run-p prettier:fix lint:fix"
|
||||
},
|
||||
"main": "src/index.ts",
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"main": "dist/index.cjs.js",
|
||||
"module": "dist/index.es.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/index.es.js",
|
||||
"require": "./dist/index.cjs.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"dependencies": {
|
||||
"axios": "^0.25.0",
|
||||
"axios": "^0.26.0",
|
||||
"js-cookie": "^3.0.1",
|
||||
"xstate": "^4.31.0"
|
||||
},
|
||||
|
||||
@@ -28,3 +28,4 @@ export type AuthEvents =
|
||||
| { type: 'SIGNED_IN' }
|
||||
| { type: 'SIGNED_OUT' }
|
||||
| { type: 'TOKEN_CHANGED' }
|
||||
| { type: 'AWAIT_EMAIL_VERIFICATION' }
|
||||
|
||||
@@ -105,7 +105,6 @@ export const createAuthMachine = ({
|
||||
states: {
|
||||
noErrors: {},
|
||||
success: {},
|
||||
needsEmailVerification: {},
|
||||
needsSmsOtp: {},
|
||||
needsMfa: {},
|
||||
failed: {
|
||||
@@ -206,7 +205,10 @@ export const createAuthMachine = ({
|
||||
invoke: {
|
||||
src: 'signInPasswordlessEmail',
|
||||
id: 'authenticatePasswordlessEmail',
|
||||
onDone: '#nhost.authentication.signedOut.needsEmailVerification',
|
||||
onDone: {
|
||||
target: '#nhost.authentication.signedOut',
|
||||
actions: 'reportAwaitEmailVerification'
|
||||
},
|
||||
onError: {
|
||||
actions: 'saveAuthenticationError',
|
||||
target: '#nhost.authentication.signedOut.failed.server'
|
||||
@@ -256,7 +258,8 @@ export const createAuthMachine = ({
|
||||
onError: [
|
||||
{
|
||||
cond: 'unverified',
|
||||
target: '#nhost.authentication.signedOut.needsEmailVerification'
|
||||
actions: 'reportAwaitEmailVerification',
|
||||
target: '#nhost.authentication.signedOut'
|
||||
},
|
||||
{
|
||||
actions: 'saveAuthenticationError',
|
||||
@@ -307,21 +310,23 @@ export const createAuthMachine = ({
|
||||
onDone: [
|
||||
{
|
||||
cond: 'hasSession',
|
||||
target: '#nhost.authentication.signedIn',
|
||||
target: 'signedIn',
|
||||
actions: ['saveSession', 'reportTokenChanged']
|
||||
},
|
||||
{
|
||||
target: '#nhost.authentication.signedOut.needsEmailVerification'
|
||||
actions: 'reportAwaitEmailVerification',
|
||||
target: 'signedOut'
|
||||
}
|
||||
],
|
||||
onError: [
|
||||
{
|
||||
cond: 'unverified',
|
||||
target: '#nhost.authentication.signedOut.needsEmailVerification'
|
||||
actions: 'reportAwaitEmailVerification',
|
||||
target: 'signedOut'
|
||||
},
|
||||
{
|
||||
actions: 'saveRegisrationError',
|
||||
target: '#nhost.authentication.signedOut.failed.server'
|
||||
target: 'signedOut.failed.server'
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -330,7 +335,7 @@ export const createAuthMachine = ({
|
||||
type: 'parallel',
|
||||
entry: ['reportSignedIn', 'cleanUrl', 'broadcastToken'],
|
||||
on: {
|
||||
SIGNOUT: '#nhost.authentication.signedOut.signingOut',
|
||||
SIGNOUT: 'signedOut.signingOut',
|
||||
DEANONYMIZE: {
|
||||
// TODO implement
|
||||
target: '.deanonymizing'
|
||||
@@ -440,6 +445,24 @@ export const createAuthMachine = ({
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
email: {
|
||||
initial: 'awaitingVerification',
|
||||
on: {
|
||||
SIGNED_IN: [
|
||||
{
|
||||
cond: 'needsVerification',
|
||||
target: '.awaitingVerification'
|
||||
},
|
||||
'.valid'
|
||||
],
|
||||
SIGNOUT: '.awaitingVerification',
|
||||
AWAIT_EMAIL_VERIFICATION: '.awaitingVerification'
|
||||
},
|
||||
states: {
|
||||
awaitingVerification: {},
|
||||
valid: {}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -447,6 +470,7 @@ export const createAuthMachine = ({
|
||||
actions: {
|
||||
reportSignedIn: send('SIGNED_IN'),
|
||||
reportSignedOut: send('SIGNED_OUT'),
|
||||
reportAwaitEmailVerification: send('AWAIT_EMAIL_VERIFICATION'),
|
||||
reportTokenChanged: send('TOKEN_CHANGED'),
|
||||
clearContextExceptRefreshToken: assign(({ refreshToken: { value } }) => {
|
||||
storageSetter(NHOST_JWT_EXPIRES_AT_KEY, null)
|
||||
@@ -562,6 +586,9 @@ export const createAuthMachine = ({
|
||||
},
|
||||
|
||||
guards: {
|
||||
needsVerification: (ctx, e) => {
|
||||
return !ctx.user || ctx.user.isAnonymous
|
||||
},
|
||||
isSignedIn: (ctx) => !!ctx.user && !!ctx.refreshToken.value && !!ctx.accessToken.value,
|
||||
noToken: (ctx) => !ctx.refreshToken.value,
|
||||
noMfaTicket: (ctx, { ticket }) => !ticket && !ctx.mfa?.ticket,
|
||||
|
||||
@@ -38,10 +38,21 @@ export interface Typegen0 {
|
||||
saveInvalidSignUpEmail: 'SIGNUP_EMAIL_PASSWORD'
|
||||
saveInvalidSignUpPassword: 'SIGNUP_EMAIL_PASSWORD'
|
||||
saveNoMfaTicketError: 'SIGNIN_MFA_TOTP'
|
||||
reportAwaitEmailVerification:
|
||||
| 'done.invoke.authenticatePasswordlessEmail'
|
||||
| 'error.platform.authenticateUserWithPassword'
|
||||
| 'done.invoke.registerUser'
|
||||
| 'error.platform.registerUser'
|
||||
saveMfaTicket: 'done.invoke.authenticateUserWithPassword'
|
||||
saveRegisrationError: 'error.platform.registerUser'
|
||||
saveRefreshAttempt: 'error.platform.refreshToken'
|
||||
reportSignedOut: 'error.platform.importRefreshToken' | 'error.platform.authenticateWithToken'
|
||||
reportSignedOut:
|
||||
| 'error.platform.importRefreshToken'
|
||||
| 'done.invoke.authenticatePasswordlessEmail'
|
||||
| 'error.platform.authenticateUserWithPassword'
|
||||
| 'done.invoke.registerUser'
|
||||
| 'error.platform.registerUser'
|
||||
| 'error.platform.authenticateWithToken'
|
||||
resetAuthenticationError: 'xstate.init'
|
||||
destroyRefreshToken: 'xstate.init'
|
||||
clearContextExceptRefreshToken: 'SIGNOUT'
|
||||
@@ -144,6 +155,11 @@ export interface Typegen0 {
|
||||
data: unknown
|
||||
}
|
||||
'error.platform.signInMfaTotp': { type: 'error.platform.signInMfaTotp'; data: unknown }
|
||||
'done.invoke.authenticatePasswordlessEmail': {
|
||||
type: 'done.invoke.authenticatePasswordlessEmail'
|
||||
data: unknown
|
||||
__tip: 'See the XState TS docs to learn how to strongly type this.'
|
||||
}
|
||||
'error.platform.registerUser': { type: 'error.platform.registerUser'; data: unknown }
|
||||
'error.platform.refreshToken': { type: 'error.platform.refreshToken'; data: unknown }
|
||||
'error.platform.authenticateWithToken': {
|
||||
@@ -160,11 +176,6 @@ export interface Typegen0 {
|
||||
__tip: 'See the XState TS docs to learn how to strongly type this.'
|
||||
}
|
||||
'error.platform.signingOut': { type: 'error.platform.signingOut'; data: unknown }
|
||||
'done.invoke.authenticatePasswordlessEmail': {
|
||||
type: 'done.invoke.authenticatePasswordlessEmail'
|
||||
data: unknown
|
||||
__tip: 'See the XState TS docs to learn how to strongly type this.'
|
||||
}
|
||||
'done.invoke.authenticatePasswordlessSms': {
|
||||
type: 'done.invoke.authenticatePasswordlessSms'
|
||||
data: unknown
|
||||
@@ -214,6 +225,7 @@ export interface Typegen0 {
|
||||
isAutoRefreshDisabled: ''
|
||||
hasRefreshToken: ''
|
||||
refreshTimerShouldRefresh: ''
|
||||
needsVerification: 'SIGNED_IN'
|
||||
}
|
||||
eventsCausingDelays: {}
|
||||
matchesStates:
|
||||
@@ -222,7 +234,6 @@ export interface Typegen0 {
|
||||
| 'authentication.signedOut'
|
||||
| 'authentication.signedOut.noErrors'
|
||||
| 'authentication.signedOut.success'
|
||||
| 'authentication.signedOut.needsEmailVerification'
|
||||
| 'authentication.signedOut.needsSmsOtp'
|
||||
| 'authentication.signedOut.needsMfa'
|
||||
| 'authentication.signedOut.failed'
|
||||
@@ -257,6 +268,9 @@ export interface Typegen0 {
|
||||
| 'token.idle.noErrors'
|
||||
| 'token.idle.error'
|
||||
| 'token.running'
|
||||
| 'email'
|
||||
| 'email.awaitingVerification'
|
||||
| 'email.valid'
|
||||
| {
|
||||
authentication?:
|
||||
| 'starting'
|
||||
@@ -268,7 +282,6 @@ export interface Typegen0 {
|
||||
signedOut?:
|
||||
| 'noErrors'
|
||||
| 'success'
|
||||
| 'needsEmailVerification'
|
||||
| 'needsSmsOtp'
|
||||
| 'needsMfa'
|
||||
| 'failed'
|
||||
@@ -301,6 +314,7 @@ export interface Typegen0 {
|
||||
}
|
||||
}
|
||||
token?: 'idle' | 'running' | { idle?: 'noErrors' | 'error' }
|
||||
email?: 'awaitingVerification' | 'valid'
|
||||
}
|
||||
tags: 'loading'
|
||||
}
|
||||
|
||||
@@ -29,39 +29,13 @@ const defaultClientStorageSetter: StorageSetter = (key, value) => {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO see https://github.com/nhost/nhost/pull/507#discussion_r865873389
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const checkStorageAccessors = (
|
||||
clientStorage: ClientStorage,
|
||||
accessors: Array<keyof ClientStorage>
|
||||
) => {
|
||||
accessors.forEach((key) => {
|
||||
if (typeof clientStorage[key] !== 'function') {
|
||||
console.error(`clientStorage.${key} is not a function`)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export const localStorageGetter = (
|
||||
clientStorageType: ClientStorageType,
|
||||
clientStorage?: ClientStorage
|
||||
): StorageGetter => {
|
||||
if (!clientStorage || clientStorageType === 'localStorage' || clientStorageType === 'web') {
|
||||
if (clientStorageType === 'localStorage' || clientStorageType === 'web') {
|
||||
return defaultClientStorageGetter
|
||||
}
|
||||
|
||||
if (clientStorageType === 'react-native') {
|
||||
// checkStorageAccessors(clientStorage, ['getItem'])
|
||||
return (key) => clientStorage.getItem?.(key)
|
||||
}
|
||||
if (clientStorageType === 'capacitor') {
|
||||
// checkStorageAccessors(clientStorage, ['get'])
|
||||
return (key) => clientStorage.get?.({ key })
|
||||
}
|
||||
if (clientStorageType === 'expo-secure-storage') {
|
||||
// checkStorageAccessors(clientStorage, ['getItemAsync'])
|
||||
return (key) => clientStorage.getItemAsync?.(key)
|
||||
}
|
||||
if (clientStorageType === 'cookie') {
|
||||
return (key) => {
|
||||
if (isBrowser) {
|
||||
@@ -71,6 +45,20 @@ export const localStorageGetter = (
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!clientStorage) {
|
||||
throw Error(
|
||||
`clientStorageType is set to '${clientStorageType}' but no clienStorage has been given`
|
||||
)
|
||||
}
|
||||
if (clientStorageType === 'react-native') {
|
||||
return (key) => clientStorage.getItem?.(key)
|
||||
}
|
||||
if (clientStorageType === 'capacitor') {
|
||||
return (key) => clientStorage.get?.({ key })
|
||||
}
|
||||
if (clientStorageType === 'expo-secure-storage') {
|
||||
return (key) => clientStorage.getItemAsync?.(key)
|
||||
}
|
||||
if (clientStorageType === 'custom') {
|
||||
if (clientStorage.getItem && clientStorage.removeItem) {
|
||||
return clientStorage.getItem
|
||||
@@ -89,25 +77,9 @@ export const localStorageSetter = (
|
||||
clientStorageType: ClientStorageType,
|
||||
clientStorage?: ClientStorage
|
||||
): StorageSetter => {
|
||||
if (!clientStorage || clientStorageType === 'localStorage' || clientStorageType === 'web') {
|
||||
if (clientStorageType === 'localStorage' || clientStorageType === 'web') {
|
||||
return defaultClientStorageSetter
|
||||
}
|
||||
|
||||
if (clientStorageType === 'react-native') {
|
||||
// checkStorageAccessors(clientStorage, ['setItem', 'removeItem'])
|
||||
return (key, value) =>
|
||||
value ? clientStorage.setItem?.(key, value) : clientStorage.removeItem?.(key)
|
||||
}
|
||||
if (clientStorageType === 'capacitor') {
|
||||
// checkStorageAccessors(clientStorage, ['set', 'remove'])
|
||||
return (key, value) =>
|
||||
value ? clientStorage.set?.({ key, value }) : clientStorage.remove?.({ key })
|
||||
}
|
||||
if (clientStorageType === 'expo-secure-storage') {
|
||||
// checkStorageAccessors(clientStorage, ['setItemAsync', 'deleteItemAsync'])
|
||||
return async (key, value) =>
|
||||
value ? clientStorage.setItemAsync?.(key, value) : clientStorage.deleteItemAsync?.(key)
|
||||
}
|
||||
if (clientStorageType === 'cookie') {
|
||||
return (key, value) => {
|
||||
if (isBrowser) {
|
||||
@@ -119,6 +91,23 @@ export const localStorageSetter = (
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!clientStorage) {
|
||||
throw Error(
|
||||
`clientStorageType is set to '${clientStorageType}' but no clienStorage has been given`
|
||||
)
|
||||
}
|
||||
if (clientStorageType === 'react-native') {
|
||||
return (key, value) =>
|
||||
value ? clientStorage.setItem?.(key, value) : clientStorage.removeItem?.(key)
|
||||
}
|
||||
if (clientStorageType === 'capacitor') {
|
||||
return (key, value) =>
|
||||
value ? clientStorage.set?.({ key, value }) : clientStorage.remove?.({ key })
|
||||
}
|
||||
if (clientStorageType === 'expo-secure-storage') {
|
||||
return async (key, value) =>
|
||||
value ? clientStorage.setItemAsync?.(key, value) : clientStorage.deleteItemAsync?.(key)
|
||||
}
|
||||
if (clientStorageType === 'custom') {
|
||||
if (!clientStorage.removeItem) {
|
||||
throw Error(
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"composite": true
|
||||
},
|
||||
"include": ["src/**/*", "types/**/*", "../../types/**/*", "tests/**/*"]
|
||||
}
|
||||
"extends": "../../config/tsconfig.base.json",
|
||||
"include": ["src"]
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user