@white-matrix/matrix-universe-auth-sdk
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

@white-matrix/matrix-universe-auth-sdk

Install

yarn add @white-matrix/matrix-universe-auth-sdk

Usage

Init auth config & Warp AuthProvider in root

import {
  AuthProvider,
  EAuthEnv,
  initAuthConfig,
} from "@white-matrix/matrix-universe-auth-sdk";
import "@white-matrix/matrix-universe-auth-sdk/dist/style.css";
import { toast, ToastContainer } from "react-toastify";

initAuthConfig({
  // env
  env: EAuthEnv.DEV,
  // toast method
  toast: (message, type) => {
    toast[type](message);
  },
  // get sub system access token by main system auth code
  getAccessToken: async (authCode: string) => {
    if (!authCode) return;
    const data = await fetch(
      `${BASE_URL}/api/auth/callback?token=${encodeURIComponent(authCode)}`,
      {
        method: "GET",
      }
    );
    if (data.status === 200) {
      return await data.text();
    } else {
      throw new Error("Failed to get access token");
    }
  },
});

ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
  <React.StrictMode>
    <ToastContainer />
    <AuthProvider>
      <App />
    </AuthProvider>
  </React.StrictMode>
);

Methods

import {
  addWallet,
  login,
  logout,
  logoutAndShowLoginModal,
  openProfileModal,
  register,
} from "@white-matrix/matrix-universe-auth-sdk";

Check is login

import { useAuthStore } from "@white-matrix/matrix-universe-auth-sdk";
const { userInfo } = useAuthStore();
// if userInfo?.userId has value, User has logged in

Readme

Keywords

none

Package Sidebar

Install

npm i @white-matrix/matrix-universe-auth-sdk

Weekly Downloads

8

Version

1.0.7

License

none

Unpacked Size

300 kB

Total Files

129

Last publish

Collaborators

  • miles_wang
  • vera_wlz
  • hexi1997
  • sleepyyj
  • chen-yu
  • kilru
  • lucklyric
  • q33357
  • xiadd