Compare commits

..

3 Commits

Author SHA1 Message Date
github-actions[bot]
94fda09575 chore: update versions (#240)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2022-03-02 13:59:14 +01:00
Pilou
38f0093c8b Fix useNhostAuth typings (#239)
* build: remove .nhost folders when performing a full `clean:all`

* fix: correct Nhost context type

* chore: changeset
2022-03-02 13:21:59 +01:00
Szilárd Dóró
9f4c44cc04 added onAuthStateChange function reference to docs, fixed some typos (#233) 2022-03-01 09:45:01 +01:00
7 changed files with 34 additions and 6 deletions

View File

@@ -12,7 +12,6 @@ Initialize a new Nhost App locally:
```sql
nhost init -n "nhost-example-app" && cd nhost-example-app
```
And initialize the GitHub repository in the same folder:
@@ -35,4 +34,4 @@ If you click on the deployment you can see that nothing was really deployed. Tha
![Deployments details](/images/cli-workflow/deployments-details.png)
Lets do some local backend changes!
Let's do some local backend changes!

View File

@@ -119,3 +119,16 @@ Reset password for a user. Calling this function sends an email to the user with
```js
const { error } = await nhost.auth.resetPassword({ email })
```
## `nhost.auth.onAuthStateChanged(event, session)`
Use `onAuthStateChanged` to add a custom function that is triggered
whenever the user's state changes. For example, from signed in to signed out or
vice versa.
```js
nhost.auth.onAuthStateChanged(({ event, session }) => {
// event = 'SIGNED_IN' | 'SIGNED_OUT'
console.log(`Auth state changed. State is now ${event} with the session: ${session}`)
})
```

View File

@@ -19,7 +19,7 @@
"prepare": "pnpm create-config",
"build": "pnpm turbo run build --scope='@nhost/*' --no-deps --include-dependencies",
"build:docs": "pnpm run build --filter=nhost-documentation",
"clean:all": "pnpm clean && rm -rf ./{{packages,examples}/*,docs}/node_modules node_modules",
"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",
"ci:version": "changeset version && pnpm install --frozen-lockfile false",

View File

@@ -1,5 +1,12 @@
# @nhost/react-auth
## 2.0.8
### Patch Changes
- 38f0093: Correct Nhost context type
`const { user } = useNhostAuth()`: user type was `null`. It is now `User | null`.
## 2.0.7
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/react-auth",
"version": "2.0.7",
"version": "2.0.8",
"description": "Nhost React client",
"license": "MIT",
"keywords": [
@@ -55,6 +55,7 @@
"react-dom": "^16.0.0 || ^17.0.0 || ^18.0.0"
},
"devDependencies": {
"@nhost/hasura-auth-js": "workspace:*",
"@types/react": "^17.0.38",
"react": "^17.0.2",
"react-dom": "^17.0.2"

View File

@@ -1,8 +1,14 @@
import React, { createContext, ReactNode, useContext, useEffect, useState } from 'react'
import type { User } from '@nhost/hasura-auth-js'
import { NhostClient } from '@nhost/nhost-js'
export const AuthContext = createContext({
type NhostContext = {
isLoading: boolean
isAuthenticated: boolean
user: User | null
}
export const AuthContext = createContext<NhostContext>({
user: null,
isLoading: true,
isAuthenticated: false
@@ -15,7 +21,7 @@ export function NhostAuthProvider({
children: ReactNode
nhost: NhostClient
}) {
const [authContext, setAuthContext] = useState({
const [authContext, setAuthContext] = useState<NhostContext>({
user: null,
isLoading: true,
isAuthenticated: false

2
pnpm-lock.yaml generated
View File

@@ -293,6 +293,7 @@ importers:
packages/react-auth:
specifiers:
'@nhost/hasura-auth-js': workspace:*
'@nhost/nhost-js': workspace:*
'@types/react': ^17.0.38
react: ^17.0.2
@@ -300,6 +301,7 @@ importers:
dependencies:
'@nhost/nhost-js': link:../nhost-js
devDependencies:
'@nhost/hasura-auth-js': link:../hasura-auth-js
'@types/react': 17.0.39
react: 17.0.2
react-dom: 17.0.2_react@17.0.2