Nhost JS SDK to handle Auth and Storage with Nhost.
https://github.com/nhost/nhost-js-sdk/compare/v3.1.0...v3.1.1-0
https://github.com/nhost/nhost-js-sdk/compare/v3.0.1-0...v3.1.0
https://github.com/nhost/nhost-js-sdk/compare/v3.0.1-0...v3.0.1-2
https://github.com/nhost/nhost-js-sdk/compare/v3.0.1-0...v3.0.1-1
https://github.com/nhost/nhost-js-sdk/compare/v3.0.0...v3.0.1-0
This major release introduces a few small (mostly renaming) breaking changes and some minor improvements to the API:
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 };
auth.changeEmailRequest()
is now auth.requestEmailChange()
auth.changeEmailChange()
is now auth.confirmEmailChange()
auth.changePasswordRequest()
is now auth.requestPasswordChange()
auth.changePasswordChange()
is now auth.confirmPasswordChange()
register()
AUTO_ACTIVATE_NEW_USERS
to false
, we will log in the user and return a promise with the session
and user
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]"
}
}
AUTO_ACTIVATE_NEW_USERS
set to false
, session
will be null
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()
session
and user
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]"
}
}
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()
login()
and register()
).Usage
const { session, user } = await auth.MFATotp(code, ticket)
logout()
logout()
also returns session
and user
set to null
.user()
{
"id": "kcf72f45-5a2d-4615-810d-96e10548bb35",
"display_name": "Nuno Pato",
"email": "[email protected]"
}
Usage
auth.user()
refreshSession()
Usage
auth.refreshSession()
Full documentation here
https://github.com/nhost/nhost-js-sdk/compare/v3.0.0-15...v3.0.0-16
https://github.com/nhost/nhost-js-sdk/compare/v3.0.0-14...v3.0.0-15
https://github.com/nhost/nhost-js-sdk/compare/v3.0.0-13...v3.0.0-14