0.5.5 • Published 6 months ago

@matchi/auth v0.5.5

Weekly downloads
-
License
-
Repository
-
Last release
6 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

6 months ago

0.5.4

6 months ago

0.5.3

7 months ago

0.5.1

7 months ago

0.5.0

9 months ago

0.4.0

10 months ago

0.3.4

11 months ago

0.3.3

11 months ago

0.3.2

11 months ago

0.3.1

11 months ago

0.3.0

11 months ago

0.2.0

12 months ago

0.1.7

12 months ago

0.1.6

12 months ago

0.1.5

12 months ago

0.1.4

12 months ago

0.1.3

12 months ago

0.1.2

12 months ago

0.1.1

12 months ago

0.1.0

12 months ago