0.5.5 • Published 7 months ago

@matchi/auth v0.5.5

Weekly downloads
-
License
-
Repository
-
Last release
7 months ago

@matchi/auth

Client package for authentication in MATCHi.

Introduction

This is the MATCHi Authentication client for frontend applications, aiming to create a common set of functions to handle authentication through the system authentication provider .

Currently supported are React Native applications build with Expo. Support for React and NextJS web applications is planned.

Installation

npm install @matchi/auth # using npm
bun install @matchi/auth # using bun
yarn add @matchi/auth # using yarn

Getting started

You should wrap your application using the AuthenticationProvider and configure the options with your application realm, clientId and redirectUri configuration.

import { useAuthentication, AuthenticationProvider } from "@matchi/auth";
import { OpenAPI } from "@matchi/api";

// Wrap your application with the configured provider
<AuthenticationProvider options={...}>
  <App />
</AuthenticationProvider>

// Use the hook to access methods and props in components
const { login, token } = useAuthentication();

// Your application should trigger the actions when needed
useEffect(() => {
  login().then(() => {
    console.log("You are logged in!")
  });
}, []);

// Watch the token and configure services when it changes
useEffect(() => {
  OpenAPI.TOKEN = token;
}, [token])

States

The following states are possible in the module, with Unavailable as the default state while being instanced and Unauthenticated as the default passive state when authentication is ready to be used:

import { AuthenticationStates } from "@matchi/auth";
const { state } = useAuthentication();

// Not ready yet and user cannot login or signup
AuthenticationStates.Unavailable;
// User is authenticated and can logout
AuthenticationStates.Authenticated;
// User is currently being authenticated (logged in)
AuthenticationStates.Authenticating;
// User is not authenticated and can login or signup
AuthenticationStates.Unauthenticated;
// User is currently being unauthenticated (logged out)
AuthenticationStates.Unauthenticating;

The following errors are possible in the module, which are thrown by rejected promises resulting from the login(), logout(), or signup() methods.

import { AuthenticationErrors } from "@matchi/auth";

// Server couldn't verify the request code sent by the client
AuthenticationErrors.UnverifiedRequestCode;
// Client couldn't identify the response code sent by the server
AuthenticationErrors.UnidentifiedResponseCode;
// There was no server response from the client request
AuthenticationErrors.MissingRequestResponse;
// There was no server discovery document found
AuthenticationErrors.MissingDiscoveryDocument;

Storage

Tokens are saved in SecureStore in native applications and localStorage in web applications. If either of these are unsupported on the device, an error will be thrown.

0.5.5

7 months ago

0.5.4

7 months ago

0.5.3

8 months ago

0.5.1

8 months ago

0.5.0

10 months ago

0.4.0

11 months ago

0.3.4

1 year ago

0.3.3

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago