@dayle-probably/use-cloud-auth

1.0.0 • Public • Published

useCloudAuth

React hook for interacting with a backend using cloud-auth.

Has not been tested with React versions below 18.2.0;

Exports:

{
  isLoggedIn,
  tokenPayload, // contains user info
  login,
  logout,
  fetchAuthenticated,
  register,
  validateInviteCode,
  createGuestAccount,
  upgradeGuestAccount,
}

Usage

Wrap your app in the Provider:

// main.jsx
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.jsx'
+import {AuthProvider} from '@dayle-probably/use-cloud-auth';

ReactDOM.createRoot(document.getElementById('root')).render(
  <React.StrictMode>
+   <AuthProvider>
      <App />
+   </AuthProvider>
  </React.StrictMode>,
)

use in your components like this:

import { useAuth } from '@dayle-probably/use-cloud-auth';

function Login() {
  const { login } = useAuth();

  // ..
}

TODO

Proper docs. Remove wouter dependency. App should handle redirects. Extract useLocalStorage hook to seperate package.

/@dayle-probably/use-cloud-auth/

    Package Sidebar

    Install

    npm i @dayle-probably/use-cloud-auth

    Weekly Downloads

    0

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    11.5 kB

    Total Files

    8

    Last publish

    Collaborators

    • dayle-probably