@matchi/auth v0.5.5
@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.
6 months ago
6 months ago
7 months ago
7 months ago
9 months ago
10 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago