Compare commits

..

10 Commits

Author SHA1 Message Date
Pilou
5ff6876aea Merge pull request #918 from nhost/changeset-release/main
chore: update versions
2022-09-05 10:54:49 +02:00
github-actions[bot]
d392ed86fb chore: update versions 2022-09-05 08:27:06 +00:00
Pilou
3bbe09c4b1 Merge pull request #917 from nhost/fix-passwordless-email-options
fix: add options to `nhost.auth.signIn({ email, options })`
2022-09-05 10:25:30 +02:00
Pierre-Louis Mercereau
a47ce29173 fix: add options to nhost.auth.signIn({ email, options }) 2022-09-05 09:57:46 +02:00
Pilou
42fba7a095 Merge pull request #907 from nhost/core-typings
fix: improve typings
2022-08-30 11:24:13 +02:00
Pierre-Louis Mercereau
0ff633760a Merge branch 'main' into core-typings 2022-08-30 11:09:05 +02:00
Pilou
6c51571182 Merge pull request #909 from nhost/bump-storage-version-0.2.4
ci: bump hasura-storage version to 0.2.4
2022-08-30 11:08:44 +02:00
Pierre-Louis Mercereau
3825a09aed ci: bump hasura-storage version to 0.2.4 2022-08-30 10:25:57 +02:00
Pierre-Louis Mercereau
1768b1e069 docs: comment types & interfaces 2022-08-30 09:23:53 +02:00
Pierre-Louis Mercereau
fba5c819ce fix: improve typings 2022-08-29 21:39:26 +02:00
93 changed files with 324 additions and 568 deletions

View File

@@ -4,7 +4,7 @@ title: signUp()
sidebar_label: signUp()
slug: /reference/javascript/auth/sign-up
description: Use `nhost.auth.signUp` to sign up a user using email and password. If you want to sign up a user using passwordless email (Magic Link), SMS, or an OAuth provider, use the `signIn` function instead.
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L103
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L102
---
# `signUp()`

View File

@@ -4,7 +4,7 @@ title: signIn()
sidebar_label: signIn()
slug: /reference/javascript/auth/sign-in
description: Use `nhost.auth.signIn` to sign in a user using email and password, passwordless (email or sms) or an external provider. `signIn` can be used to sign in a user 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#L146
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L145
---
# `signIn()`

View File

@@ -4,7 +4,7 @@ title: signOut()
sidebar_label: signOut()
slug: /reference/javascript/auth/sign-out
description: Use `nhost.auth.signOut` to sign out the user.
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L231
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L233
---
# `signOut()`

View File

@@ -4,7 +4,7 @@ title: resetPassword()
sidebar_label: resetPassword()
slug: /reference/javascript/auth/reset-password
description: Use `nhost.auth.resetPassword` to reset the password for a user. This will send a reset-password link in an email to the user. When the user clicks the reset-password link the user is automatically signed-in. Once signed-in, the user can change their password using `nhost.auth.changePassword()`.
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L247
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L249
---
# `resetPassword()`

View File

@@ -4,7 +4,7 @@ title: changePassword()
sidebar_label: changePassword()
slug: /reference/javascript/auth/change-password
description: Use `nhost.auth.changePassword` to change the password for the signed-in user. The old password is not needed. In case the user is not signed-in, a password reset ticket needs to be provided.
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L263
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L265
---
# `changePassword()`

View File

@@ -4,7 +4,7 @@ title: sendVerificationEmail()
sidebar_label: sendVerificationEmail()
slug: /reference/javascript/auth/send-verification-email
description: Use `nhost.auth.sendVerificationEmail` to send a verification email to the specified email. The email contains a verification-email link. When the user clicks the verification-email link their email is verified.
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L279
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L284
---
# `sendVerificationEmail()`

View File

@@ -4,7 +4,7 @@ title: changeEmail()
sidebar_label: changeEmail()
slug: /reference/javascript/auth/change-email
description: Use `nhost.auth.changeEmail` to change a user's email. This will send a confirm-email-change link in an email to the new email. Once the user clicks on the confirm-email-change link the email will be change to the new email.
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L298
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L303
---
# `changeEmail()`

View File

@@ -4,7 +4,7 @@ title: deanonymize()
sidebar_label: deanonymize()
slug: /reference/javascript/auth/deanonymize
description: Use `nhost.auth.deanonymize` to deanonymize a user.
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L314
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L319
---
# `deanonymize()`

View File

@@ -4,7 +4,7 @@ title: onTokenChanged()
sidebar_label: onTokenChanged()
slug: /reference/javascript/auth/on-token-changed
description: Use `nhost.auth.onTokenChanged` to add a custom function that runs every time the access or refresh token is changed.
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L357
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L362
---
# `onTokenChanged()`

View File

@@ -4,7 +4,7 @@ title: onAuthStateChanged()
sidebar_label: onAuthStateChanged()
slug: /reference/javascript/auth/on-auth-state-changed
description: Use `nhost.auth.onAuthStateChanged` to add a custom function that runs every time the authentication status of the user changes. E.g. add a custom function that runs every time the authentication status changes from signed-in to signed-out.
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L392
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L397
---
# `onAuthStateChanged()`

View File

@@ -4,7 +4,7 @@ title: isAuthenticated()
sidebar_label: isAuthenticated()
slug: /reference/javascript/auth/is-authenticated
description: Use `nhost.auth.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#L434
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L439
---
# `isAuthenticated()`

View File

@@ -4,7 +4,7 @@ title: isAuthenticatedAsync()
sidebar_label: isAuthenticatedAsync()
slug: /reference/javascript/auth/is-authenticated-async
description: Use `nhost.auth.isAuthenticatedAsync` to wait (await) for any internal authentication network requests to finish and then return the authentication status.
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L452
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L457
---
# `isAuthenticatedAsync()`

View File

@@ -4,7 +4,7 @@ title: getAuthenticationStatus()
sidebar_label: getAuthenticationStatus()
slug: /reference/javascript/auth/get-authentication-status
description: Use `nhost.auth.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#L478
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L483
---
# `getAuthenticationStatus()`

View File

@@ -4,7 +4,7 @@ title: getAccessToken()
sidebar_label: getAccessToken()
slug: /reference/javascript/auth/get-access-token
description: Use `nhost.auth.getAccessToken` to get the access token of the user.
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L508
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L513
---
# `getAccessToken()`

View File

@@ -4,7 +4,7 @@ title: getDecodedAccessToken()
sidebar_label: getDecodedAccessToken()
slug: /reference/javascript/auth/get-decoded-access-token
description: Use `nhost.auth.getDecodedAccessToken` to get the decoded access token of the user.
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L523
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L528
---
# `getDecodedAccessToken()`

View File

@@ -4,7 +4,7 @@ title: getHasuraClaims()
sidebar_label: getHasuraClaims()
slug: /reference/javascript/auth/get-hasura-claims
description: Use `nhost.auth.getHasuraClaims` to get the Hasura claims of the user.
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L540
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L545
---
# `getHasuraClaims()`

View File

@@ -4,7 +4,7 @@ title: getHasuraClaim()
sidebar_label: getHasuraClaim()
slug: /reference/javascript/auth/get-hasura-claim
description: Use `nhost.auth.getHasuraClaim` to get the value of a specific Hasura claim of the user.
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L558
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L563
---
# `getHasuraClaim()`

View File

@@ -4,7 +4,7 @@ title: refreshSession()
sidebar_label: refreshSession()
slug: /reference/javascript/auth/refresh-session
description: Use `nhost.auth.refreshSession` to refresh the session with either the current internal refresh token or an external refresh token.
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L581
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L586
---
# `refreshSession()`

View File

@@ -4,7 +4,7 @@ title: getSession()
sidebar_label: getSession()
slug: /reference/javascript/auth/get-session
description: Use `nhost.auth.getSession()` to get the session of the user.
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L625
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L627
---
# `getSession()`

View File

@@ -4,7 +4,7 @@ title: getUser()
sidebar_label: getUser()
slug: /reference/javascript/auth/get-user
description: Use `nhost.auth.getUser()` to get the signed-in user.
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L640
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L642
---
# `getUser()`

View File

@@ -4,7 +4,7 @@ title: HasuraAuthClient
sidebar_label: Auth
description: No description provided.
slug: /reference/javascript/auth
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L60
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/hasura-auth-client.ts#L59
---
# `HasuraAuthClient`

View File

@@ -1,18 +0,0 @@
---
# ⚠️ AUTO-GENERATED CONTENT. DO NOT EDIT THIS FILE DIRECTLY! ⚠️
title: ApiChangeEmailResponse
sidebar_label: ApiChangeEmailResponse
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L182
---
# `ApiChangeEmailResponse`
## Parameters
---
**<span className="parameter-name">error</span>** <span className="optional-status">required</span> `null` | `ErrorPayload`
---

View File

@@ -1,18 +0,0 @@
---
# ⚠️ AUTO-GENERATED CONTENT. DO NOT EDIT THIS FILE DIRECTLY! ⚠️
title: ApiChangePasswordResponse
sidebar_label: ApiChangePasswordResponse
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L174
---
# `ApiChangePasswordResponse`
## Parameters
---
**<span className="parameter-name">error</span>** <span className="optional-status">required</span> `null` | `ErrorPayload`
---

View File

@@ -1,18 +0,0 @@
---
# ⚠️ AUTO-GENERATED CONTENT. DO NOT EDIT THIS FILE DIRECTLY! ⚠️
title: ApiDeanonymizeResponse
sidebar_label: ApiDeanonymizeResponse
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L186
---
# `ApiDeanonymizeResponse`
## Parameters
---
**<span className="parameter-name">error</span>** <span className="optional-status">required</span> `null` | `ErrorPayload`
---

View File

@@ -1,16 +0,0 @@
---
# ⚠️ AUTO-GENERATED CONTENT. DO NOT EDIT THIS FILE DIRECTLY! ⚠️
title: ApiRefreshTokenResponse
sidebar_label: ApiRefreshTokenResponse
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L162
---
# `ApiRefreshTokenResponse`
```ts
type ApiRefreshTokenResponse =
| { session: null; error: ErrorPayload }
| { session: Session; error: null }
```

View File

@@ -1,18 +0,0 @@
---
# ⚠️ AUTO-GENERATED CONTENT. DO NOT EDIT THIS FILE DIRECTLY! ⚠️
title: ApiResetPasswordResponse
sidebar_label: ApiResetPasswordResponse
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L170
---
# `ApiResetPasswordResponse`
## Parameters
---
**<span className="parameter-name">error</span>** <span className="optional-status">required</span> `null` | `ErrorPayload`
---

View File

@@ -1,18 +0,0 @@
---
# ⚠️ AUTO-GENERATED CONTENT. DO NOT EDIT THIS FILE DIRECTLY! ⚠️
title: ApiSendVerificationEmailResponse
sidebar_label: ApiSendVerificationEmailResponse
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L178
---
# `ApiSendVerificationEmailResponse`
## Parameters
---
**<span className="parameter-name">error</span>** <span className="optional-status">required</span> `null` | `ErrorPayload`
---

View File

@@ -1,29 +0,0 @@
---
# ⚠️ AUTO-GENERATED CONTENT. DO NOT EDIT THIS FILE DIRECTLY! ⚠️
title: ApiSignInData
sidebar_label: ApiSignInData
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L151
---
# `ApiSignInData`
## Parameters
---
**<span className="parameter-name">session</span>** <span className="optional-status">required</span> [`Session`](/reference/docgen/javascript/auth/types/session)
| Property | Type | Required | Notes |
| :------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------- | :------: | :---- |
| <span className="parameter-name"><span className="light-grey">session.</span>user</span> | `null` \| [`User`](/reference/docgen/javascript/auth/types/user) | ✔️ | |
| <span className="parameter-name"><span className="light-grey">session.</span>refreshToken</span> | `string` | ✔️ | |
| <span className="parameter-name"><span className="light-grey">session.</span>accessTokenExpiresIn</span> | `number` | ✔️ | |
| <span className="parameter-name"><span className="light-grey">session.</span>accessToken</span> | `string` | ✔️ | |
---
**<span className="parameter-name">mfa</span>** <span className="optional-status">required</span> `null` | [`Mfa`](/reference/docgen/javascript/auth/types/mfa)
---

View File

@@ -1,16 +0,0 @@
---
# ⚠️ AUTO-GENERATED CONTENT. DO NOT EDIT THIS FILE DIRECTLY! ⚠️
title: ApiSignInResponse
sidebar_label: ApiSignInResponse
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L155
---
# `ApiSignInResponse`
```ts
type ApiSignInResponse =
| { data: ApiSignInData; error: null }
| { data: null; error: ErrorPayload }
```

View File

@@ -1,18 +0,0 @@
---
# ⚠️ AUTO-GENERATED CONTENT. DO NOT EDIT THIS FILE DIRECTLY! ⚠️
title: ApiSignOutResponse
sidebar_label: ApiSignOutResponse
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L166
---
# `ApiSignOutResponse`
## Parameters
---
**<span className="parameter-name">error</span>** <span className="optional-status">required</span> `null` | `ErrorPayload`
---

View File

@@ -1,16 +0,0 @@
---
# ⚠️ AUTO-GENERATED CONTENT. DO NOT EDIT THIS FILE DIRECTLY! ⚠️
title: ApiSignUpEmailPasswordResponse
sidebar_label: ApiSignUpEmailPasswordResponse
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L147
---
# `ApiSignUpEmailPasswordResponse`
```ts
type ApiSignUpEmailPasswordResponse =
| { session: null; error: ErrorPayload }
| { session: Session; error: null }
```

View File

@@ -4,7 +4,7 @@ title: AuthChangeEvent
sidebar_label: AuthChangeEvent
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L135
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L100
---
# `AuthChangeEvent`

View File

@@ -4,7 +4,7 @@ title: AuthChangedFunction
sidebar_label: AuthChangedFunction
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L137
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L102
---
# `AuthChangedFunction`
@@ -12,6 +12,6 @@ custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-j
```ts
type AuthChangedFunction = () => (
event: AuthChangeEvent,
session: Session | null
session: NhostSession | null
) => void
```

View File

@@ -4,7 +4,7 @@ title: ChangeEmailParams
sidebar_label: ChangeEmailParams
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L106
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L82
---
# `ChangeEmailParams`

View File

@@ -4,7 +4,7 @@ title: ChangePasswordParams
sidebar_label: ChangePasswordParams
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L96
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L72
---
# `ChangePasswordParams`

View File

@@ -4,7 +4,7 @@ title: DeanonymizeParams
sidebar_label: DeanonymizeParams
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L111
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L87
---
# `DeanonymizeParams`

View File

@@ -1,18 +0,0 @@
---
# ⚠️ AUTO-GENERATED CONTENT. DO NOT EDIT THIS FILE DIRECTLY! ⚠️
title: Headers
sidebar_label: Headers
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L140
---
# `Headers`
## Parameters
---
**<span className="parameter-name">Authorization</span>** <span className="optional-status">optional</span> `string`
---

View File

@@ -1,18 +0,0 @@
---
# ⚠️ AUTO-GENERATED CONTENT. DO NOT EDIT THIS FILE DIRECTLY! ⚠️
title: Mfa
sidebar_label: Mfa
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L143
---
# `Mfa`
## Parameters
---
**<span className="parameter-name">ticket</span>** <span className="optional-status">required</span> `string`
---

View File

@@ -4,11 +4,11 @@ title: OnTokenChangedFunction
sidebar_label: OnTokenChangedFunction
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L139
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L104
---
# `OnTokenChangedFunction`
```ts
type OnTokenChangedFunction = () => (session: Session | null) => void
type OnTokenChangedFunction = () => (session: NhostSession | null) => void
```

View File

@@ -4,7 +4,7 @@ title: Provider
sidebar_label: Provider
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/core/src/types.ts#L140
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/core/src/types.ts#L141
---
# `Provider`

View File

@@ -4,7 +4,7 @@ title: ResetPasswordParams
sidebar_label: ResetPasswordParams
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L91
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L67
---
# `ResetPasswordParams`

View File

@@ -4,7 +4,7 @@ title: SendVerificationEmailParams
sidebar_label: SendVerificationEmailParams
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L101
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L77
---
# `SendVerificationEmailParams`

View File

@@ -1,30 +0,0 @@
---
# ⚠️ AUTO-GENERATED CONTENT. DO NOT EDIT THIS FILE DIRECTLY! ⚠️
title: Session
sidebar_label: Session
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L23
---
# `Session`
## 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> `null` | [`User`](/reference/docgen/javascript/auth/types/user)
---

View File

@@ -4,7 +4,7 @@ title: SignInEmailPasswordOtpParams
sidebar_label: SignInEmailPasswordOtpParams
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L59
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L35
---
# `SignInEmailPasswordOtpParams`

View File

@@ -4,7 +4,7 @@ title: SignInEmailPasswordParams
sidebar_label: SignInEmailPasswordParams
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L54
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L30
---
# `SignInEmailPasswordParams`

View File

@@ -4,7 +4,7 @@ title: SignInParams
sidebar_label: SignInParams
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L83
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L59
---
# `SignInParams`

View File

@@ -4,7 +4,7 @@ title: SignInPasswordlessEmailParams
sidebar_label: SignInPasswordlessEmailParams
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L64
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L40
---
# `SignInPasswordlessEmailParams`

View File

@@ -4,7 +4,7 @@ title: SignInPasswordlessSmsOtpParams
sidebar_label: SignInPasswordlessSmsOtpParams
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L74
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L50
---
# `SignInPasswordlessSmsOtpParams`

View File

@@ -4,7 +4,7 @@ title: SignInPasswordlessSmsParams
sidebar_label: SignInPasswordlessSmsParams
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L69
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L45
---
# `SignInPasswordlessSmsParams`

View File

@@ -1,34 +0,0 @@
---
# ⚠️ AUTO-GENERATED CONTENT. DO NOT EDIT THIS FILE DIRECTLY! ⚠️
title: SignInReponse
sidebar_label: SignInReponse
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L124
---
# `SignInReponse`
## Parameters
---
**<span className="parameter-name">session</span>** <span className="optional-status">required</span> `null` | [`Session`](/reference/docgen/javascript/auth/types/session)
---
**<span className="parameter-name">error</span>** <span className="optional-status">required</span> `null` | `ErrorPayload`
---
**<span className="parameter-name">mfa</span>** <span className="optional-status">optional</span> `{ enabled: boolean, ticket: string }`
---
**<span className="parameter-name">providerUrl</span>** <span className="optional-status">optional</span> `string`
---
**<span className="parameter-name">provider</span>** <span className="optional-status">optional</span> `string`
---

View File

@@ -1,34 +0,0 @@
---
# ⚠️ AUTO-GENERATED CONTENT. DO NOT EDIT THIS FILE DIRECTLY! ⚠️
title: SignInResponse
sidebar_label: SignInResponse
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L45
---
# `SignInResponse`
## Parameters
---
**<span className="parameter-name">session</span>** <span className="optional-status">required</span> `null` | [`Session`](/reference/docgen/javascript/auth/types/session)
---
**<span className="parameter-name">mfa</span>** <span className="optional-status">required</span> `null` | `{ ticket: string }`
---
**<span className="parameter-name">error</span>** <span className="optional-status">required</span> `null` | `ErrorPayload`
---
**<span className="parameter-name">providerUrl</span>** <span className="optional-status">optional</span> `string`
---
**<span className="parameter-name">provider</span>** <span className="optional-status">optional</span> `string`
---

View File

@@ -4,7 +4,7 @@ title: SignInWithProviderOptions
sidebar_label: SignInWithProviderOptions
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L78
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L54
---
# `SignInWithProviderOptions`

View File

@@ -4,7 +4,7 @@ title: SignUpEmailPasswordParams
sidebar_label: SignUpEmailPasswordParams
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L31
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L23
---
# `SignUpEmailPasswordParams`

View File

@@ -4,7 +4,7 @@ title: SignUpParams
sidebar_label: SignUpParams
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L37
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L29
---
# `SignUpParams`

View File

@@ -1,16 +0,0 @@
---
# ⚠️ AUTO-GENERATED CONTENT. DO NOT EDIT THIS FILE DIRECTLY! ⚠️
title: SignUpResponse
sidebar_label: SignUpResponse
description: No description provided.
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/hasura-auth-js/src/utils/types.ts#L39
---
# `SignUpResponse`
```ts
type SignUpResponse =
| { session: null; error: ErrorPayload }
| { session: Session | null; error: null }
```

View File

@@ -4,7 +4,7 @@ title: User
sidebar_label: User
description: User information
displayed_sidebar: referenceSidebar
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/core/src/types.ts#L93
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/core/src/types.ts#L94
---
# `User`

View File

@@ -4,7 +4,7 @@ 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#L128
custom_edit_url: https://github.com/nhost/nhost/edit/main/packages/core/src/types.ts#L129
---
# `NhostSession`

View File

@@ -7,7 +7,7 @@ services:
auth:
image: nhost/hasura-auth:0.10.0
storage:
image: nhost/hasura-storage:0.2.3
image: nhost/hasura-storage:0.2.4
auth:
access_control:
email:

View File

@@ -7,7 +7,7 @@ services:
auth:
image: nhost/hasura-auth:0.10.0
storage:
image: nhost/hasura-storage:0.2.3
image: nhost/hasura-storage:0.2.4
auth:
access_control:
email:

View File

@@ -7,7 +7,7 @@ services:
auth:
image: nhost/hasura-auth:0.10.0
storage:
image: nhost/hasura-storage:0.2.3
image: nhost/hasura-storage:0.2.4
auth:
access_control:
email:

View File

@@ -7,7 +7,7 @@ services:
auth:
image: nhost/hasura-auth:0.10.0
storage:
image: nhost/hasura-storage:0.2.3
image: nhost/hasura-storage:0.2.4
auth:
access_control:
email:

View File

@@ -7,7 +7,7 @@ services:
auth:
image: nhost/hasura-auth:0.10.0
storage:
image: nhost/hasura-storage:0.2.3
image: nhost/hasura-storage:0.2.4
auth:
access_control:
email:

View File

@@ -7,7 +7,7 @@ services:
auth:
image: nhost/hasura-auth:0.10.0
storage:
image: nhost/hasura-storage:0.2.3
image: nhost/hasura-storage:0.2.4
auth:
access_control:
email:

View File

@@ -7,7 +7,7 @@ services:
auth:
image: nhost/hasura-auth:0.10.0
storage:
image: nhost/hasura-storage:0.2.3
image: nhost/hasura-storage:0.2.4
auth:
access_control:
email:

View File

@@ -1,4 +1,4 @@
# Docker image versions used in the cloud
hasura: v2.10.1
auth: 0.10.0
storage: 0.2.3
storage: 0.2.4

View File

@@ -1,5 +1,11 @@
# @nhost/apollo
## 0.5.28
### Patch Changes
- @nhost/nhost-js@1.4.11
## 0.5.27
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/apollo",
"version": "0.5.27",
"version": "0.5.28",
"description": "Nhost Apollo Client library",
"license": "MIT",
"keywords": [

View File

@@ -3,7 +3,7 @@ import { assign, createMachine, send } from 'xstate'
import { AuthClient } from '../client'
import { ErrorPayload, INVALID_EMAIL_ERROR } from '../errors'
import { nhostApiClient } from '../hasura-auth'
import { ChangeEmailOptions } from '../types'
import { ChangeEmailOptions, ChangeEmailResponse } from '../types'
import { rewriteRedirectTo } from '../utils'
import { isValidEmail } from '../validators'
@@ -20,6 +20,10 @@ export type ChangeEmailEvents =
| { type: 'SUCCESS' }
| { type: 'ERROR'; error: ErrorPayload | null }
export type ChangeEmailServices = {
request: { data: ChangeEmailResponse }
}
export type ChangeEmailMachine = ReturnType<typeof createChangeEmailMachine>
export const createChangeEmailMachine = ({ backendUrl, clientUrl, interpreter }: AuthClient) => {
@@ -28,7 +32,8 @@ export const createChangeEmailMachine = ({ backendUrl, clientUrl, interpreter }:
{
schema: {
context: {} as ChangeEmailContext,
events: {} as ChangeEmailEvents
events: {} as ChangeEmailEvents,
services: {} as ChangeEmailServices
},
tsTypes: {} as import('./change-email.typegen').Typegen0,
preserveActionOrder: true,
@@ -70,6 +75,7 @@ export const createChangeEmailMachine = ({ backendUrl, clientUrl, interpreter }:
actions: {
saveInvalidEmailError: assign({ error: (_) => INVALID_EMAIL_ERROR }),
saveRequestError: assign({
// * Untyped action payload. See https://github.com/statelyai/xstate/issues/3037
error: (_, { data: { error } }: any) => error
}),
reportError: send((ctx) => ({ type: 'ERROR', error: ctx.error })),

View File

@@ -3,6 +3,7 @@ import { assign, createMachine, send } from 'xstate'
import { AuthClient } from '../client'
import { ErrorPayload, INVALID_PASSWORD_ERROR } from '../errors'
import { nhostApiClient } from '../hasura-auth'
import { ChangePasswordResponse } from '../types'
import { isValidPassword } from '../validators'
export type ChangePasswordContext = {
@@ -17,6 +18,10 @@ export type ChangePasswordEvents =
| { type: 'SUCCESS' }
| { type: 'ERROR'; error: ErrorPayload | null }
export type ChangePasswordServices = {
requestChange: { data: ChangePasswordResponse }
}
export type ChangePasswordMachine = ReturnType<typeof createChangePasswordMachine>
export const createChangePasswordMachine = ({ backendUrl, interpreter }: AuthClient) => {
@@ -25,7 +30,8 @@ export const createChangePasswordMachine = ({ backendUrl, interpreter }: AuthCli
{
schema: {
context: {} as ChangePasswordContext,
events: {} as ChangePasswordEvents
events: {} as ChangePasswordEvents,
services: {} as ChangePasswordServices
},
tsTypes: {} as import('./change-password.typegen').Typegen0,
preserveActionOrder: true,
@@ -67,6 +73,7 @@ export const createChangePasswordMachine = ({ backendUrl, interpreter }: AuthCli
actions: {
saveInvalidPasswordError: assign({ error: (_) => INVALID_PASSWORD_ERROR }),
saveRequestError: assign({
// * Untyped action payload. See https://github.com/statelyai/xstate/issues/3037
error: (_, { data: { error } }: any) => error
}),
reportError: send((ctx) => ({ type: 'ERROR', error: ctx.error })),
@@ -77,7 +84,7 @@ export const createChangePasswordMachine = ({ backendUrl, interpreter }: AuthCli
},
services: {
requestChange: (_, { password, ticket }) =>
api.post<string, { data: { error?: ErrorPayload } }>(
api.post<string, ChangePasswordResponse>(
'/user/password',
{ newPassword: password, ticket: ticket },
{

View File

@@ -1,4 +1,4 @@
import type { AxiosRequestConfig, AxiosResponse } from 'axios'
import type { AxiosRequestConfig } from 'axios'
import { assign, createMachine, send } from 'xstate'
import {
@@ -18,7 +18,21 @@ import {
} from '../errors'
import { nhostApiClient } from '../hasura-auth'
import { localStorageGetter, localStorageSetter } from '../storage'
import { AuthOptions, Mfa, NhostSession } from '../types'
import {
AuthOptions,
DeanonymizeResponse,
NhostSession,
NhostSessionResponse,
PasswordlessEmailResponse,
PasswordlessSmsOtpResponse,
PasswordlessSmsResponse,
RefreshSessionResponse,
SignInAnonymousResponse,
SignInMfaTotpResponse,
SignInResponse,
SignOutResponse,
SignUpResponse
} from '../types'
import { getParameterByName, removeParameterFromWindow, rewriteRedirectTo } from '../utils'
import { isValidEmail, isValidPassword, isValidPhoneNumber, isValidTicket } from '../validators'
@@ -40,6 +54,18 @@ export interface AuthMachineOptions extends AuthOptions {
export type AuthMachine = ReturnType<typeof createAuthMachine>
type AuthServices = {
signInPassword: { data: SignInResponse }
passwordlessSms: { data: PasswordlessSmsResponse | DeanonymizeResponse }
passwordlessSmsOtp: { data: PasswordlessSmsOtpResponse }
passwordlessEmail: { data: PasswordlessEmailResponse | DeanonymizeResponse }
signInAnonymous: { data: SignInAnonymousResponse }
signInMfaTotp: { data: SignInMfaTotpResponse }
refreshToken: { data: NhostSessionResponse }
signout: { data: SignOutResponse }
signUpEmailPassword: { data: SignUpResponse }
importRefreshToken: { data: NhostSessionResponse }
}
// TODO actions typings
export const createAuthMachine = ({
@@ -56,19 +82,21 @@ export const createAuthMachine = ({
const storageGetter = clientStorageGetter || localStorageGetter(clientStorageType, clientStorage)
const storageSetter = clientStorageSetter || localStorageSetter(clientStorageType, clientStorage)
const api = nhostApiClient(backendUrl)
const postRequest = async <T = any, R = AxiosResponse<T>, D = any>(
const postRequest = async <T = any, D = any>(
url: string,
data?: D,
config?: AxiosRequestConfig<D>
): Promise<R> => {
): Promise<T> => {
const result = await api.post(url, data, config)
return result.data
}
return createMachine(
{
schema: {
context: {} as AuthContext,
events: {} as AuthEvents
events: {} as AuthEvents,
services: {} as AuthServices
},
tsTypes: {} as import('./index.typegen').Typegen0,
context: INITIAL_MACHINE_CONTEXT,
@@ -429,33 +457,37 @@ export const createAuthMachine = ({
// * Save session in the context, and persist the refresh token and the jwt expiration outside of the machine
saveSession: assign({
user: (_, { data }: any) => data?.session?.user,
accessToken: (_, { data }: any) => {
if (data.session.accessTokenExpiresIn) {
const nextRefresh = new Date(
Date.now() + data.session.accessTokenExpiresIn * 1_000
).toISOString()
storageSetter(NHOST_JWT_EXPIRES_AT_KEY, nextRefresh)
} else {
storageSetter(NHOST_JWT_EXPIRES_AT_KEY, null)
user: (_, { data }) => data?.session?.user || null,
accessToken: (_, { data }) => {
if (data.session) {
const { accessTokenExpiresIn, accessToken } = data.session
const nextRefresh = new Date(Date.now() + accessTokenExpiresIn * 1_000)
storageSetter(NHOST_JWT_EXPIRES_AT_KEY, nextRefresh.toISOString())
return {
value: accessToken,
expiresAt: nextRefresh
}
}
storageSetter(NHOST_JWT_EXPIRES_AT_KEY, null)
return {
value: data?.session?.accessToken,
expiresAt: new Date(Date.now() + data?.session?.accessTokenExpiresIn * 1_000)
value: null,
expiresAt: null
}
},
refreshToken: (_, { data }: any) => {
storageSetter(NHOST_REFRESH_TOKEN_KEY, data.session.refreshToken)
return { value: data?.session?.refreshToken }
refreshToken: (_, { data }) => {
const refreshToken = data.session?.refreshToken || null
if (refreshToken) {
storageSetter(NHOST_REFRESH_TOKEN_KEY, refreshToken)
}
return { value: refreshToken }
}
}),
saveMfaTicket: assign({
mfa: (_, e: any) => e.data?.mfa
mfa: (_, e) => e.data?.mfa
}),
resetTimer: assign({
refreshTimer: (ctx, e) => ({
refreshTimer: (_) => ({
startedAt: new Date(),
attempts: 0,
lastAttempt: null
@@ -472,12 +504,17 @@ export const createAuthMachine = ({
// * Authentication errors
saveAuthenticationError: assign({
errors: ({ errors }, { data: { error } }: any) => ({ ...errors, authentication: error })
// * Untyped action payload. See https://github.com/statelyai/xstate/issues/3037
errors: ({ errors }, { data: { error } }: any) => ({
...errors,
authentication: error
})
}),
resetErrors: assign({
errors: (_) => ({})
}),
saveRegistrationError: assign({
// * Untyped action payload. See https://github.com/statelyai/xstate/issues/3037
errors: ({ errors }, { data: { error } }: any) => ({ ...errors, registration: error })
}),
destroyRefreshToken: assign({
@@ -541,14 +578,15 @@ export const createAuthMachine = ({
return remaining <= 0
},
// * Authentication errors
// * Untyped action payload. See https://github.com/statelyai/xstate/issues/3037
unverified: (_, { data: { error } }: any) =>
error.status === 401 &&
// * legacy: don't use the message contents to determine if the email is unverified, but the error type (error.error)
(error.message === 'Email is not verified' || error.error === 'unverified-user'),
// * Event guards
hasSession: (_, e: any) => !!e.data?.session,
hasMfaTicket: (_, e: any) => !!e.data?.mfa
hasSession: (_, e) => !!e.data?.session,
hasMfaTicket: (_, e) => !!e.data?.mfa
},
services: {
@@ -559,7 +597,7 @@ export const createAuthMachine = ({
if (!isValidPassword(password)) {
return Promise.reject({ error: INVALID_PASSWORD_ERROR })
}
return postRequest('/signin/email-password', {
return postRequest<SignInResponse>('/signin/email-password', {
email,
password
})
@@ -632,7 +670,7 @@ export const createAuthMachine = ({
},
signInAnonymous: (_) => postRequest('/signin/anonymous'),
signInMfaTotp: (context, data) => {
const ticket = data.ticket || context.mfa?.ticket
const ticket: string | undefined = data.ticket || context.mfa?.ticket
if (!ticket) {
return Promise.reject({ error: NO_MFA_TICKET_ERROR })
}
@@ -640,20 +678,17 @@ export const createAuthMachine = ({
return Promise.reject({ error: INVALID_MFA_TICKET_ERROR })
}
return postRequest<
{ mfa: Mfa | null; session: NhostSession | null },
{ mfa: Mfa | null; session: NhostSession | null }
>('/signin/mfa/totp', {
return postRequest('/signin/mfa/totp', {
ticket,
otp: data.otp
})
},
refreshToken: async (ctx, event) => {
const refreshToken = event.type === 'TRY_TOKEN' ? event.token : ctx.refreshToken.value
const session = await postRequest('/token', {
const session = await postRequest<RefreshSessionResponse>('/token', {
refreshToken
})
return { session }
return { session, error: null }
},
signout: (ctx, e) =>
postRequest('/signout', {
@@ -662,13 +697,13 @@ export const createAuthMachine = ({
}),
signUpEmailPassword: async (context, { email, password, options }) => {
if (!isValidEmail(email)) {
return Promise.reject({ error: INVALID_EMAIL_ERROR })
return Promise.reject<SignUpResponse>({ error: INVALID_EMAIL_ERROR })
}
if (!isValidPassword(password)) {
return Promise.reject({ error: INVALID_PASSWORD_ERROR })
return Promise.reject<SignUpResponse>({ error: INVALID_PASSWORD_ERROR })
}
if (context.user?.isAnonymous) {
return postRequest(
return postRequest<SignUpResponse>(
'/user/deanonymize',
{
signInMethod: 'email-password',
@@ -683,7 +718,7 @@ export const createAuthMachine = ({
}
)
} else {
return postRequest('/signup/email-password', {
return postRequest<SignUpResponse>('/signup/email-password', {
email,
password,
options: rewriteRedirectTo(clientUrl, options)
@@ -697,17 +732,18 @@ export const createAuthMachine = ({
const urlToken = getParameterByName('refreshToken') || null
if (urlToken) {
try {
const session = await postRequest('/token', {
const session = await postRequest<NhostSession>('/token', {
refreshToken: urlToken
})
return { session }
return { session, error: null }
} catch (exception) {
error = (exception as { error: ValidationErrorPayload }).error
}
} else {
const error = getParameterByName('error')
if (error) {
return Promise.reject<{ error: ValidationErrorPayload }>({
return Promise.reject<NhostSessionResponse>({
session: null,
error: {
status: VALIDATION_ERROR_CODE,
error,
@@ -720,16 +756,15 @@ export const createAuthMachine = ({
const storageToken = await storageGetter(NHOST_REFRESH_TOKEN_KEY)
if (storageToken) {
try {
const session = await postRequest('/token', {
const session = await postRequest<NhostSession>('/token', {
refreshToken: storageToken
})
return { session }
return { session, error: null }
} catch (exception) {
error = (exception as { error: ValidationErrorPayload }).error
}
}
return Promise.reject<{ error: ValidationErrorPayload }>({ error })
return Promise.reject<NhostSessionResponse>({ error })
}
}
}

View File

@@ -3,7 +3,7 @@ import { assign, createMachine, send } from 'xstate'
import { AuthClient } from '../client'
import { ErrorPayload, INVALID_EMAIL_ERROR } from '../errors'
import { nhostApiClient } from '../hasura-auth'
import { ResetPasswordOptions } from '../types'
import { ResetPasswordOptions, ResetPasswordResponse } from '../types'
import { rewriteRedirectTo } from '../utils'
import { isValidEmail } from '../validators'
@@ -19,6 +19,10 @@ export type ResetPasswordEvents =
| { type: 'SUCCESS' }
| { type: 'ERROR'; error: ErrorPayload | null }
export type ResetPasswordServices = {
requestChange: { data: ResetPasswordResponse }
}
export type ResetPasswordMachine = ReturnType<typeof createResetPasswordMachine>
export const createResetPasswordMachine = ({ backendUrl, clientUrl }: AuthClient) => {
@@ -27,7 +31,8 @@ export const createResetPasswordMachine = ({ backendUrl, clientUrl }: AuthClient
{
schema: {
context: {} as ResetPasswordContext,
events: {} as ResetPasswordEvents
events: {} as ResetPasswordEvents,
services: {} as ResetPasswordServices
},
tsTypes: {} as import('./reset-password.typegen').Typegen0,
preserveActionOrder: true,
@@ -69,6 +74,7 @@ export const createResetPasswordMachine = ({ backendUrl, clientUrl }: AuthClient
actions: {
saveInvalidEmailError: assign({ error: (_) => INVALID_EMAIL_ERROR }),
saveRequestError: assign({
// * Untyped action payload. See https://github.com/statelyai/xstate/issues/3037
error: (_, { data: { error } }: any) => error
}),
reportError: send((ctx) => ({ type: 'ERROR', error: ctx.error })),
@@ -79,7 +85,7 @@ export const createResetPasswordMachine = ({ backendUrl, clientUrl }: AuthClient
},
services: {
requestChange: (_, { email, options }) =>
api.post<string, { data: { error?: ErrorPayload } }>('/user/password/reset', {
api.post<string, ResetPasswordResponse>('/user/password/reset', {
email,
options: rewriteRedirectTo(clientUrl, options)
})

View File

@@ -3,7 +3,7 @@ import { assign, createMachine, send } from 'xstate'
import { AuthClient } from '../client'
import { ErrorPayload, INVALID_EMAIL_ERROR } from '../errors'
import { nhostApiClient } from '../hasura-auth'
import { SendVerificationEmailOptions } from '../types'
import { SendVerificationEmailOptions, SendVerificationEmailResponse } from '../types'
import { rewriteRedirectTo } from '../utils'
import { isValidEmail } from '../validators'
@@ -20,6 +20,10 @@ export type SendVerificationEmailEvents =
| { type: 'SUCCESS' }
| { type: 'ERROR'; error: ErrorPayload | null }
export type SendVerificationEmailServices = {
request: { data: SendVerificationEmailResponse }
}
export type SendVerificationEmailMachine = ReturnType<typeof createSendVerificationEmailMachine>
export const createSendVerificationEmailMachine = ({ backendUrl, clientUrl }: AuthClient) => {
const api = nhostApiClient(backendUrl)
@@ -27,7 +31,8 @@ export const createSendVerificationEmailMachine = ({ backendUrl, clientUrl }: Au
{
schema: {
context: {} as SendVerificationEmailContext,
events: {} as SendVerificationEmailEvents
events: {} as SendVerificationEmailEvents,
services: {} as SendVerificationEmailServices
},
tsTypes: {} as import('./send-verification-email.typegen').Typegen0,
preserveActionOrder: true,
@@ -69,6 +74,7 @@ export const createSendVerificationEmailMachine = ({ backendUrl, clientUrl }: Au
actions: {
saveInvalidEmailError: assign({ error: (_) => INVALID_EMAIL_ERROR }),
saveRequestError: assign({
// * Untyped action payload. See https://github.com/statelyai/xstate/issues/3037
error: (_, { data: { error } }: any) => error
}),
reportError: send((ctx) => ({ type: 'ERROR', error: ctx.error })),
@@ -79,10 +85,13 @@ export const createSendVerificationEmailMachine = ({ backendUrl, clientUrl }: Au
},
services: {
request: async (_, { email, options }) => {
const res = await api.post('/user/email/send-verification-email', {
email,
options: rewriteRedirectTo(clientUrl, options)
})
const res = await api.post<SendVerificationEmailResponse>(
'/user/email/send-verification-email',
{
email,
options: rewriteRedirectTo(clientUrl, options)
}
)
return res.data
}
}

View File

@@ -2,6 +2,7 @@
import { InterpreterFrom } from 'xstate'
import { ErrorPayload } from './errors'
import { AuthMachine } from './machines'
import { StorageGetter, StorageSetter } from './storage'
@@ -207,3 +208,61 @@ export type ClientStorageType =
| 'react-native'
| 'web'
| 'cookie'
// Hasura-auth API response types
interface NullableErrorResponse {
error: ErrorPayload | null
}
/** session payload from common hasura-auth responses */
export type NhostSessionResponse =
| { session: null; error: ErrorPayload }
| { session: NhostSession | null; error: null }
/** payload from hasura-auth endpoint /signin/email-password */
export interface SignInResponse {
session: NhostSession | null
mfa: {
ticket: string
} | null
error: ErrorPayload | null
}
/** payload from hasura-auth endpoint /signup/email-password */
export type SignUpResponse = NhostSessionResponse
/** payload from hasura-auth endpoint /token */
export type RefreshSessionResponse = NhostSession
/** payload from hasura-auth endpoint /signout */
export interface SignOutResponse extends NullableErrorResponse {}
/** payload from hasura-auth endpoint /user/password/reset */
export interface ResetPasswordResponse extends NullableErrorResponse {}
/** payload from hasura-auth endpoint /user/password */
export interface ChangePasswordResponse extends NullableErrorResponse {}
/** payload from hasura-auth endpoint /user/email/send-verification-email */
export interface SendVerificationEmailResponse extends NullableErrorResponse {}
/** payload from hasura-auth endpoint /user/email/change */
export interface ChangeEmailResponse extends NullableErrorResponse {}
/** payload from hasura-auth endpoint /user/deanonymize */
export interface DeanonymizeResponse extends NullableErrorResponse {}
/** payload from hasura-auth endpoint /signin/passwordless/email */
export interface PasswordlessEmailResponse extends NullableErrorResponse {}
/** payload from hasura-auth endpoint /signin/passwordless/sms */
export interface PasswordlessSmsResponse extends NullableErrorResponse {}
/** payload from hasura-auth endpoint /signin/anonymous */
export type SignInAnonymousResponse = NhostSessionResponse
/** payload from hasura-auth endpoint /signin/anonymous */
export type PasswordlessSmsOtpResponse = NhostSessionResponse
/** payload from hasura-auth endpoint /signin/mfa/totp */
export type SignInMfaTotpResponse = NhostSessionResponse

View File

@@ -1,5 +1,11 @@
# @nhost/hasura-auth-js
## 1.4.2
### Patch Changes
- a47ce291: Add options to `nhost.auth.signIn({ email, options })`
## 1.4.1
### Patch Changes

View File

@@ -7,7 +7,7 @@ services:
auth:
image: nhost/hasura-auth:0.10.0
storage:
image: nhost/hasura-storage:0.2.3
image: nhost/hasura-storage:0.2.4
auth:
access_control:
email:

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/hasura-auth-js",
"version": "1.4.1",
"version": "1.4.2",
"description": "Hasura-auth client",
"license": "MIT",
"keywords": [

View File

@@ -5,40 +5,42 @@ import {
AuthClient,
AuthInterpreter,
changeEmailPromise,
ChangeEmailResponse,
changePasswordPromise,
ChangePasswordResponse,
createChangeEmailMachine,
createChangePasswordMachine,
createResetPasswordMachine,
createSendVerificationEmailMachine,
DeanonymizeResponse,
EMAIL_NEEDS_VERIFICATION,
encodeQueryParameters,
ErrorPayload,
INVALID_REFRESH_TOKEN,
JWTClaims,
JWTHasuraClaims,
NhostSessionResponse,
NO_REFRESH_TOKEN,
resetPasswordPromise,
ResetPasswordResponse,
rewriteRedirectTo,
sendVerificationEmailPromise,
SendVerificationEmailResponse,
signInAnonymousPromise,
signInEmailPasswordlessPromise,
signInEmailPasswordPromise,
signInMfaTotpPromise,
SignInResponse,
signInSmsPasswordlessOtpPromise,
signInSmsPasswordlessPromise,
signOutPromise,
SignOutResponse,
signUpEmailPasswordPromise,
SignUpResponse,
TOKEN_REFRESHER_RUNNING_ERROR
} from '@nhost/core'
import { getAuthenticationResult, getSession, isBrowser } from './utils/helpers'
import {
ApiChangeEmailResponse,
ApiChangePasswordResponse,
ApiDeanonymizeResponse,
ApiResetPasswordResponse,
ApiSendVerificationEmailResponse,
ApiSignOutResponse,
AuthChangedFunction,
ChangeEmailParams,
ChangePasswordParams,
@@ -47,11 +49,8 @@ import {
OnTokenChangedFunction,
ResetPasswordParams,
SendVerificationEmailParams,
Session,
SignInParams,
SignInResponse,
SignUpParams,
SignUpResponse
SignUpParams
} from './utils/types'
/**
@@ -143,7 +142,9 @@ export class HasuraAuthClient {
*
* @docs https://docs.nhost.io/reference/javascript/auth/sign-in
*/
async signIn(params: SignInParams): Promise<SignInResponse> {
async signIn(
params: SignInParams
): Promise<SignInResponse & { providerUrl?: string; provider?: string }> {
const interpreter = await this.waitUntilReady()
// * Sign in with a social provider (OAuth)
@@ -177,7 +178,8 @@ export class HasuraAuthClient {
// * Passwordless Email (magic link)
if ('email' in params) {
const { error } = await signInEmailPasswordlessPromise(interpreter, params.email)
const { email, options } = params
const { error } = await signInEmailPasswordlessPromise(interpreter, email, options)
return {
session: null,
mfa: null,
@@ -228,7 +230,7 @@ export class HasuraAuthClient {
*
* @docs https://docs.nhost.io/reference/javascript/auth/sign-out
*/
async signOut(params?: { all?: boolean }): Promise<ApiSignOutResponse> {
async signOut(params?: { all?: boolean }): Promise<SignOutResponse> {
const interpreter = await this.waitUntilReady()
const { error } = await signOutPromise(interpreter, params?.all)
return { error }
@@ -244,7 +246,7 @@ export class HasuraAuthClient {
*
* @docs https://docs.nhost.io/reference/javascript/auth/reset-password
*/
async resetPassword({ email, options }: ResetPasswordParams): Promise<ApiResetPasswordResponse> {
async resetPassword({ email, options }: ResetPasswordParams): Promise<ResetPasswordResponse> {
const service = interpret(createResetPasswordMachine(this._client)).start()
const { error } = await resetPasswordPromise(service, email, options)
return { error }
@@ -260,7 +262,10 @@ export class HasuraAuthClient {
*
* @docs https://docs.nhost.io/reference/javascript/auth/change-password
*/
async changePassword({ newPassword, ticket }: ChangePasswordParams): Promise<ApiChangePasswordResponse> {
async changePassword({
newPassword,
ticket
}: ChangePasswordParams): Promise<ChangePasswordResponse> {
const service = interpret(createChangePasswordMachine(this._client)).start()
const { error } = await changePasswordPromise(service, newPassword, ticket)
return { error }
@@ -279,7 +284,7 @@ export class HasuraAuthClient {
async sendVerificationEmail({
email,
options
}: SendVerificationEmailParams): Promise<ApiSendVerificationEmailResponse> {
}: SendVerificationEmailParams): Promise<SendVerificationEmailResponse> {
const service = interpret(createSendVerificationEmailMachine(this._client)).start()
const { error } = await sendVerificationEmailPromise(service, email, options)
return { error }
@@ -295,7 +300,7 @@ export class HasuraAuthClient {
*
* @docs https://docs.nhost.io/reference/javascript/auth/change-email
*/
async changeEmail({ newEmail, options }: ChangeEmailParams): Promise<ApiChangeEmailResponse> {
async changeEmail({ newEmail, options }: ChangeEmailParams): Promise<ChangeEmailResponse> {
const service = interpret(createChangeEmailMachine(this._client)).start()
const { error } = await changeEmailPromise(service, newEmail, options)
return { error }
@@ -311,7 +316,7 @@ export class HasuraAuthClient {
*
* @docs https://docs.nhost.io/reference/javascript/auth/deanonymize
*/
async deanonymize(params: DeanonymizeParams): Promise<ApiDeanonymizeResponse> {
async deanonymize(params: DeanonymizeParams): Promise<DeanonymizeResponse> {
const interpreter = await this.waitUntilReady()
if (params.signInMethod === 'passwordless') {
if (params.connection === 'email') {
@@ -578,10 +583,7 @@ export class HasuraAuthClient {
*
* @docs https://docs.nhost.io/reference/javascript/auth/refresh-session
*/
async refreshSession(refreshToken?: string): Promise<{
session: Session | null
error: ErrorPayload | null
}> {
async refreshSession(refreshToken?: string): Promise<NhostSessionResponse> {
try {
const interpreter = await this.waitUntilReady()
return new Promise((resolve) => {

View File

@@ -1,10 +1,8 @@
import { AuthContext, SessionActionHandlerResult } from '@nhost/core'
import { Session, SignUpResponse } from './types'
import { AuthContext, NhostSession, SessionActionHandlerResult, SignUpResponse } from '@nhost/core'
export const isBrowser = () => typeof window !== 'undefined'
export const getSession = (context?: AuthContext): Session | null => {
export const getSession = (context?: AuthContext): NhostSession | null => {
if (
!context ||
!context.accessToken.value ||

View File

@@ -1,7 +1,7 @@
import {
AuthClient,
AuthOptions,
ErrorPayload,
NhostSession,
PasswordlessOptions,
Provider,
ProviderOptions,
@@ -19,14 +19,6 @@ export interface NhostAuthConstructorParams extends AuthOptions {
autoLogin?: boolean
}
// TODO remove and use NhostSession instead
export interface Session {
accessToken: string
accessTokenExpiresIn: number
refreshToken: string
user: User | null
}
// Sign Up
export interface SignUpEmailPasswordParams {
email: string
@@ -35,22 +27,6 @@ export interface SignUpEmailPasswordParams {
}
export type SignUpParams = SignUpEmailPasswordParams
export type SignUpResponse =
| { session: null; error: ErrorPayload }
| { session: Session | null; error: null }
// Sign In
export interface SignInResponse {
session: Session | null
mfa: {
ticket: string
} | null
error: ErrorPayload | null
providerUrl?: string
provider?: string
}
export interface SignInEmailPasswordParams {
email: string
password: string
@@ -121,68 +97,8 @@ export type DeanonymizeParams =
connection: 'sms'
} & SignInPasswordlessSmsParams)
export interface SignInReponse {
session: Session | null
error: ErrorPayload | null
mfa?: {
enabled: boolean
ticket: string
}
providerUrl?: string
provider?: string
}
export type AuthChangeEvent = 'SIGNED_IN' | 'SIGNED_OUT'
export type AuthChangedFunction = (event: AuthChangeEvent, session: Session | null) => void
export type AuthChangedFunction = (event: AuthChangeEvent, session: NhostSession | null) => void
export type OnTokenChangedFunction = (session: Session | null) => void
export interface Headers {
Authorization?: string
}
export interface Mfa {
ticket: string
}
export type ApiSignUpEmailPasswordResponse =
| { session: null; error: ErrorPayload }
| { session: Session; error: null }
export interface ApiSignInData {
session: Session
mfa: Mfa | null
}
export type ApiSignInResponse =
| {
data: ApiSignInData
error: null
}
| { data: null; error: ErrorPayload }
export type ApiRefreshTokenResponse =
| { session: null; error: ErrorPayload }
| { session: Session; error: null }
export interface ApiSignOutResponse {
error: ErrorPayload | null
}
export interface ApiResetPasswordResponse {
error: ErrorPayload | null
}
export interface ApiChangePasswordResponse {
error: ErrorPayload | null
}
export interface ApiSendVerificationEmailResponse {
error: ErrorPayload | null
}
export interface ApiChangeEmailResponse {
error: ErrorPayload | null
}
export interface ApiDeanonymizeResponse {
error: ErrorPayload | null
}
export type OnTokenChangedFunction = (session: NhostSession | null) => void

View File

@@ -7,7 +7,7 @@ services:
auth:
image: nhost/hasura-auth:0.10.0
storage:
image: nhost/hasura-storage:0.2.3
image: nhost/hasura-storage:0.2.4
auth:
access_control:
email:

View File

@@ -1,5 +1,12 @@
# @nhost/nextjs
## 1.7.4
### Patch Changes
- @nhost/nhost-js@1.4.11
- @nhost/react@0.12.4
## 1.7.3
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/nextjs",
"version": "1.7.3",
"version": "1.7.4",
"description": "Nhost NextJS library",
"license": "MIT",
"keywords": [

View File

@@ -1,5 +1,12 @@
# @nhost/nhost-js
## 1.4.11
### Patch Changes
- Updated dependencies [a47ce291]
- @nhost/hasura-auth-js@1.4.2
## 1.4.10
### Patch Changes

View File

@@ -7,7 +7,7 @@ services:
auth:
image: nhost/hasura-auth:0.10.0
storage:
image: nhost/hasura-storage:0.2.3
image: nhost/hasura-storage:0.2.4
auth:
access_control:
email:

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/nhost-js",
"version": "1.4.10",
"version": "1.4.11",
"description": "Nhost JavaScript SDK",
"license": "MIT",
"keywords": [

View File

@@ -1,5 +1,12 @@
# @nhost/react-apollo
## 4.7.4
### Patch Changes
- @nhost/apollo@0.5.28
- @nhost/react@0.12.4
## 4.7.3
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/react-apollo",
"version": "4.7.3",
"version": "4.7.4",
"description": "Nhost React Apollo client",
"license": "MIT",
"keywords": [

View File

@@ -1,5 +1,13 @@
# @nhost/react-auth
## 3.5.4
### Patch Changes
- Updated dependencies [a47ce291]
- @nhost/hasura-auth-js@1.4.2
- @nhost/react@0.12.4
## 3.5.3
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/react-auth",
"version": "3.5.3",
"version": "3.5.4",
"description": "Nhost React client",
"license": "MIT",
"keywords": [

View File

@@ -1,5 +1,11 @@
# @nhost/react
## 0.12.4
### Patch Changes
- @nhost/nhost-js@1.4.11
## 0.12.3
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/react",
"version": "0.12.3",
"version": "0.12.4",
"description": "Nhost React library",
"license": "MIT",
"keywords": [

View File

@@ -1,5 +1,11 @@
# @nhost/vue
## 0.4.4
### Patch Changes
- @nhost/nhost-js@1.4.11
## 0.4.3
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@nhost/vue",
"version": "0.4.3",
"version": "0.4.4",
"description": "Nhost Vue library",
"license": "MIT",
"keywords": [