Skip to content

nick92/nhost-js-sdk

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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';
import { BACKEND_ENDPOINT } from '../config';

const config = {
  endpoint: 'https://backend-xxxxxx.nhost.io/'
};

export default new nhost(config);

Usage across in your app

import nhost from '../nhost';

Auth

Register

try {
  await nhost.register(username, password);
} catch (e) {
  // handle error
}

Login

try {
  await nhost.login(username, password);
} catch (e) {
  // handle error
}

Logout

  nhost.logout();

onAuthStateChanged

nhost.onAuthStateChanged(data => {
  console.log('auth state changed!');
  console.log({data});
});

Activate account

try {
  await nhost.activate_account(secret_token);
} catch (e) {
  // handle error
}

New password

try {
  await nhost.new_password(secret_token, new_password);
} catch (e) {
  // handle error
}

Storage

Upload file(s)

try {
  await nhost.upload(path, files);
} catch (e) {
  // handle error
}

Get file url

try {
  await nhost.url(file_path);
} catch (e) {
  // handle error
}

React Native

For React Native you can pass in asyncStorage for nhost to use instead of the default localStorage.

import nhost from 'nhost-js-sdk';
import { AsyncStorage } from 'react-native';
import { BACKEND_ENDPOINT } from '../config';

const config = {
  endpoint: 'https://backend-xxxxxx.nhost.io/'
  storage: AsyncStorage
};

export default new nhost(config);

About

Nhost JavaScript SDK

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%