@nbcom/auth
TypeScript icon, indicating that this package has built-in type declarations

0.6.0 • Public • Published

Auth flow

N|Solid

Work auth flow context that enables any component to get the current auth state user type and rerender if it changes

  • React/TypeScript
  • Redux
  • NextJS
  • Magic

Features

  • UserProvider includes a user type and a setter function to change it
  • useJWTAuthentication checks for a VERIFY cookie and sets the authorization flag isAuthorized=true. If the user is logged in, it sends a request to refresh the token
  • setAuthCookie Callback for set expire auth cookies
  • Logout hook

Installation

@nbcom/auth requires Node.js v16+, @nbcom/api to run.

Install the package

npm install @nbcom/auth

Development

Using user provider

import { UserProvider } from '@nbcom/auth'

  <UserProvider>
    <Template>
      <Component {...pageProps} />
    </Template>
  </UserProvider>

Using logout hook

You must create proxy file pages/api/removeAuthCookiesProxy.ts with your domain like 'someurl.ru'

import { removeAuthCookies } from "@nbcom/auth";

export default removeAuthCookies('domain');

Then you can use the hook logOut

import { useLogOut } from '@nbcom/auth'

const { logOut } = useLogOut();
<Button onClick={logOut}> Exit from acc</Button>

Boolean flag && set type user

import { useUser } from '@nbcom/auth'
const { isJuridicalUser, changeUserType, isAuthorized } = useUser();

Good luck

Readme

Keywords

none

Package Sidebar

Install

npm i @nbcom/auth

Weekly Downloads

13

Version

0.6.0

License

MIT

Unpacked Size

141 kB

Total Files

47

Last publish

Collaborators

  • nbcom