This repository was archived by the owner on Jan 28, 2022. It is now read-only.
Releases: nhost/nhost-js-sdk
Releases · nhost/nhost-js-sdk
v3.1.1-0: Merge pull request #81 from migsar/http-only-cookies
- moved test folder and added .npmignore file 8d93a4e
- release refrehs token lock after session data has been set ea4c7f9
- Merge pull request #81 from migsar/http-only-cookies 9d3d34c
- fix: allow refreshToken to be called without payload 4ed5234
- fix: allow refreshSession to pass initRefreshToken 5062572
- Merge pull request #77 from adevofficial/master d438f7e
- fix(sdk): Resolved the issue with onTokenChanged cc58dcc
- Merge pull request #76 from nhost/dependabot/npm_and_yarn/ws-7.4.6 73caf1a
- Merge pull request #68 from nhost/passwordless 5c67fa4
- Bump ws from 7.4.3 to 7.4.6 b1877cf
- Merge pull request #74 from nhost/dependabot/npm_and_yarn/hosted-git-info-2.8.9 1f26099
- Merge pull request #73 from nhost/dependabot/npm_and_yarn/lodash-4.17.21 371ac56
- Bump hosted-git-info from 2.8.8 to 2.8.9 d48bed1
- Bump lodash from 4.17.20 to 4.17.21 e72c976
- Update Auth.ts cb4ec76
- refactor: apply requested changes 0cc3b1b
- feat: rename to magic link b9fbc7d
- tests: fix fe4d3ab
- tests: add testnhostclient 64dc40a
- config: docker use test a0ef35e
v3.1.0
- updated Hasura to latest stabile version 9713b46
- Merge pull request #59 from shyndman/master 121818a
- Merge pull request #61 from nhost/storage-updates 3a4b92f
- Merge pull request #62 from komninoschat/feature/is-authenticated-async 98a9ebd
- Merge pull request #60 from komninoschat/feature/custom-client-storage aa8496a
- putString works 90c62e1
- check to start with 24355d3
- Merge pull request #56 from komninoschat/master 2803a8e
- Merge branch 'master' into master 4856358
- Merge pull request #57 from nhost/bugfix/correct-setintervals f3979f0
- Add missing type annotations in Auth.test.ts f45d625
- Correct two incorrect expectations in Auth.test.ts related to JWT 3adf4bb
- Correct register() signature in Auth.test.ts 9ec0ceb
- Remove unused sleep() function from Auth.test.ts 541ea92
- Add missing dependency on @types/fs_extras fd43da5
- add custom client storage type 468dee8
- add isAuthenticatedAsync and AuthChangedFunction d3bc405
- tests working again 80070c3
- Correct setInterval bf91cd1
- export UserConfig type 5787b25
v3.0.1-2: Merge pull request #56 from komninoschat/master
- Merge branch 'master' into storage-updates 492ff6d
- putString works 90c62e1
- check to start with 24355d3
- Merge pull request #56 from komninoschat/master 2803a8e
- Merge pull request #57 from nhost/bugfix/correct-setintervals f3979f0
- tests working again 80070c3
- Correct setInterval bf91cd1
- export UserConfig type 5787b25
v3.0.1-1
v3.0.1-0
v3.0.0
This major release introduces a few small (mostly renaming) breaking changes and some minor improvements to the API:
Breaking change - It refers to the way the client is created and initialized:
Before:
import nhost from "nhost-js-sdk";
const config = {
base_url: "https://backend-url.nhost.app",
};
nhost.initializeApp(config);
const auth = nhost.auth();
const storage = nhost.storage();
export { auth, storage };
Now:
import { createClient } from 'nhost-js-sdk'
// createClient returns an instance of NhostClient
const nhostClient = createClient({
baseURL: 'https://backend-url.nhost.app',
})
// auth and storage are now properties of NhostClient
const auth = nhostClient.auth;
const storage = nhostClient.storage;
export { auth, storage };
Breaking change - functions renamed:
auth.changeEmailRequest()
is nowauth.requestEmailChange()
auth.changeEmailChange()
is nowauth.confirmEmailChange()
auth.changePasswordRequest()
is nowauth.requestPasswordChange()
auth.changePasswordChange()
is nowauth.confirmPasswordChange()
Improvements and additions to the API
register()
- Unless you have set
AUTO_ACTIVATE_NEW_USERS
tofalse
, we will log in the user and return a promise with thesession
anduser
data. Because the user gets logged in on registration, you don't have to redirect your users to/login
anymore.
{
"session": {
"jwt_token": "e3MmYZSJdLCJ4LWhhjE0MDg3Nzc3fQ.d4kdsiBjD3MpPpbNNbaMt-gyHHVXwrSvrAtVcEQ_jB8",
"jwt_expires_in": 900000,
"user": {
"id": "kcf72f45-5a2d-4615-810d-96e10548bb35",
"display_name": "[email protected]",
"email": "[email protected]"
},
"refresh_token": "dd69aafd-71f6-4f97-be93-9bdbfb192fe6"
},
"user": {
"id": "kcf72f45-5a2d-4615-810d-96e10548bb35",
"display_name": "[email protected]",
"email": "[email protected]"
}
}
- If you have indeed
AUTO_ACTIVATE_NEW_USERS
set tofalse
,session
will benull
because we can't log in the user.
{
"session": null,
"user": {
"id": "kcf72f45-5a2d-4615-810d-96e10548bb35",
"display_name": "[email protected]",
"email": "[email protected]"
}
}
Usage
const { session, user } = await auth.register({ email, password }) // notice the object being passed
login()
- A promise with the
session
anduser
data is returned:
{
"session": {
"jwt_token": "e3MmYZSJdLCJ4LWhhjE0MDg3Nzc3fQ.d4kdsiBjD3MpPpbNNbaMt-gyHHVXwrSvrAtVcEQ_jB8",
"jwt_expires_in": 900000,
"user": {
"id": "kcf72f45-5a2d-4615-810d-96e10548bb35",
"display_name": "[email protected]",
"email": "[email protected]"
},
"refresh_token": "dd69aafd-71f6-4f97-be93-9bdbfb192fe6"
},
"user": {
"id": "kcf72f45-5a2d-4615-810d-96e10548bb35",
"display_name": "[email protected]",
"email": "[email protected]"
}
}
- If the user has MFA enabled, an
mfa
object is added and the response looks like this instead:
{
"session": null,
"user": null,
"mfa": {
"ticket": "762ea295-4a12-436f-b8fc-36b91aefb28e"
},
}
Usage
const { session, user } = await auth.login({ email, password }) // notice the object being passed
// in case MFA is enabled
const { mfa } = await auth.login({ email, password })
MFATotp()
- Returns an object with the user and corresponding session as a promise (same as
login()
andregister()
).
Usage
const { session, user } = await auth.MFATotp(code, ticket)
logout()
- For the sake of API consistency,
logout()
also returnssession
anduser
set tonull
.
Additions to the API
user()
- Returns an object for the current logged in user or null otherwise
{
"id": "kcf72f45-5a2d-4615-810d-96e10548bb35",
"display_name": "Nuno Pato",
"email": "[email protected]"
}
Usage
auth.user()
refreshSession()
- Explicitly calls refresh token
Usage
auth.refreshSession()
Full documentation here