Nhost JS SDK to handle Auth and Storage.
npm install --save nhost-js-sdk
In ex /src/nhost/index.js
:
import nhost from 'nhost-js-sdk';
const config = {
endpoint: 'https://backend-xxxx.nhost.app',
};
nhost.initializeApp(config);
const auth = nhost.auth();
const storage = nhost.storage();
export {
auth,
storage
};
import { auth, storage } from 'src/nhost/index.js';
auth.register(email, password);
auth.login(email, password);
auth.logout();
auth.onAuthStateChanged(logged_in => {
console.log('auth state changed!');
console.log({logged_in});
});
auth.isAuthenticated();
auth.getJWTToken();
auth.getClaim('x-hasura-user-id');
auth.activate(<ticket>);
Note: The user must be logged in.
auth.changeEmail(new_email);
auth.changeEmailRequest(new_email);
auth.changeEmailChange(ticket);
auth.changePassword(old_password, new_password);
auth.changePasswordRequest(email);
auth.changePasswordChange(new_password, ticket);
storage.put(path, file, metadata?, onUploadProgress?);
storage.delete(path);
auth.getMetadata(path);