Skip to content

Commit

Permalink
Catchup with PRs from legacy repository (#191)
Browse files Browse the repository at this point in the history
* fix: correct roles type in User. See nhost/hasura-auth-js#15

* feat: add metadata option see nhost/hasura-auth-js#18

* fix: correct types

fix #190

* Remove comment

* Bump Auth and hasura versions

* Create dirty-turkeys-fetch.md
  • Loading branch information
plmercereau committed Feb 21, 2022
1 parent 9e94363 commit a880583
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
7 changes: 7 additions & 0 deletions .changeset/dirty-turkeys-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@nhost/hasura-auth-js": patch
"@nhost-examples/testing-project": patch
---

- Improve typings (close [this PR](https://github.com/nhost/hasura-auth-js/pull/15))
- Add the metadata field introduced in [hasura-auth 0.2.0](https://github.com/nhost/hasura-auth/releases/tag/v0.2.0) (close [this PR](https://github.com/nhost/hasura-auth-js/pull/18))
4 changes: 2 additions & 2 deletions examples/testing-project/nhost/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ services:
mailhog:
port: 8025
hasura:
version: v2.1.0
version: v2.2.0
environment:
hasura_graphql_enable_remote_schema_permissions: false
auth:
version: sha-c328aa7
version: 0.2.1
auth:
access_control:
email:
Expand Down
11 changes: 5 additions & 6 deletions packages/hasura-auth-js/src/hasura-auth-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import {
ApiError,
ApiResetPasswordResponse,
ApiSendVerificationEmailResponse,
ApiSignInResponse,
ApiSignOutResponse,
AuthChangedFunction,
AuthChangeEvent,
ChangeEmailParams,
Expand Down Expand Up @@ -105,7 +107,6 @@ export class HasuraAuthClient {
this.initAuthLoading = true

this.session = null
// this.user = null;

this.api = new HasuraAuthApi({ url: this.url })

Expand Down Expand Up @@ -313,7 +314,7 @@ export class HasuraAuthClient {
*
* @docs https://docs.nhost.io/TODO
*/
async signOut(params?: { all?: boolean }): Promise<unknown> {
async signOut(params?: { all?: boolean }): Promise<ApiSignOutResponse> {
const refreshToken = await this._getItem(NHOST_REFRESH_TOKEN)

this._clearSession()
Expand All @@ -333,10 +334,8 @@ export class HasuraAuthClient {
*
* @docs https://docs.nhost.io/TODO
*/
async verifyEmail(params: { email: string; ticket: string }): Promise<unknown> {
const { data, error } = await this.api.verifyEmail(params)

return { data, error }
async verifyEmail(params: { email: string; ticket: string }): Promise<ApiSignInResponse> {
return await this.api.verifyEmail(params)
}

/**
Expand Down
6 changes: 5 additions & 1 deletion packages/hasura-auth-js/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface User {
email?: string
isAnonymous: boolean
defaultRole: string
roles: Record<string, string>
roles: string[]
}

export interface Session {
Expand All @@ -32,6 +32,7 @@ export interface SignUpEmailPasswordParams {
defaultRole?: string
displayName?: string
redirectTo?: string
metadata?: Record<string, unknown>
}
}

Expand All @@ -55,6 +56,7 @@ export interface SignInPasswordlessEmailParams {
defaultRole?: string
displayName?: string
redirectTo?: string
metadata?: Record<string, unknown>
}
}

Expand All @@ -66,6 +68,7 @@ export interface SignInPasswordlessSmsParams {
defaultRole?: string
displayName?: string
redirectTo?: string
metadata?: Record<string, unknown>
}
}

Expand All @@ -92,6 +95,7 @@ export interface SignInWithProviderOptions {
defaultRole?: string
displayName?: string
redirectTo?: string
metadata?: Record<string, unknown>
}
}

Expand Down
18 changes: 18 additions & 0 deletions packages/hasura-auth-js/tests/sign-up.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ describe('sign-up', () => {
expect(session).toBeNull()
})

test('sign up with metadata', async () => {
const email = faker.internet.email().toLocaleLowerCase()
const password = faker.internet.password(8)

const { session, error } = await auth.signUp({
email,
password,
options: {
metadata: {
birthDate: '1990-01-01'
}
}
})

expect(error).toBeNull()
expect(session).toBeNull()
})

it('sign up with options', async () => {
const email = faker.internet.email().toLocaleLowerCase()
const password = faker.internet.password(8)
Expand Down

1 comment on commit a880583

@vercel
Copy link

@vercel vercel bot commented on a880583 Feb 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.