Package Exports
- nhost-js-sdk
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (nhost-js-sdk) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Nhost JS SDK
Nhost JS SDK to handle Auth and Storage.
Installation
npm install --save nhost-js-sdk
Setup
In ex /src/nhost/index.js
:
import nhost from 'nhost-js-sdk';
const config = {
endpoint: process.env.REACT_APP_BACKEND_ENDPOINT,
};
nhost.initializeApp(config);
const auth = nhost.auth();
const storage = nhost.storage();
export {
auth,
storage
};
Usage auth and storage across in your app
import { auth, storage } from 'src/nhost/index.js';
Auth
Register
await auth.register(email, password);
Login
await auth.login(email, password);
Logout
auth.logout();
onAuthStateChanged
auth.onAuthStateChanged(data => {
console.log('auth state changed!');
console.log({data});
});
Storage
Upload file
metadata
and onUploadProgress
is optional
await storage.put(path, file, metadata, onUploadProgress);
Get file
Go to https://backend-[id].nhost.app/storage/o/${path}
.
Delete file
await storage.delete(path);