react-hass-auth
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

react-hass-auth

Home Assistant authentication + React Hooks, with Typescript

NPM

Easily add Home Assistant authentication to your React application. This is a thin wrapper over the home-assistant-js-websocket library for easily accessing its authentication functionality in your app, with React Context and Hooks. Types are provided.

Typescript

Library is written in TypeScript. File an issue if you find any problems.

Install

yarn add react-netlify-identity

Usage

When you call useHassAuth(), you can destructure these variables and methods:

  • authed: boolean | undefined: if the user is logged in, undefined while loading
  • connection: Connection | undefined: the home-assistant-js-websocket connection object once established
  • loading: boolean: if we are determining auth state
  • login(hassUrl?: string): function to authenticate against provided Home Assistant instance URL (optional if provided through HassAuthContextProvider)
  • logout(): logs the user out
  • _hassUrl: string | undefined: the hassUrl used in login method
import React from 'react';

import { HassAuthContextProvider } from 'react-hass-auth';

const App = () => {
    const url = 'http://hassio.local:8123'; // Supply the url of your Home Assistant instance. If left out, you are required to specify it when calling login.

    return (
        <HassAuthContextProvider hassUrl={url}>
            {/* rest of your app */}
        </HassAuthContextProvider>
    );
};

License

MIT © nielsrowinbik

Readme

Keywords

none

Package Sidebar

Install

npm i react-hass-auth

Weekly Downloads

1

Version

0.1.1

License

MIT

Unpacked Size

424 kB

Total Files

15

Last publish

Collaborators

  • nielsrowinbik