README
react-hass-auth
Home Assistant authentication + React Hooks, with Typescript
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 loadingconnection: Connection | undefined
: thehome-assistant-js-websocket
connection object once establishedloading: boolean
: if we are determining auth statelogin(hassUrl?: string)
: function to authenticate against provided Home Assistant instance URL (optional if provided throughHassAuthContextProvider
)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