@white-matrix/world3-ai-auth-sdk
v2.9.38
Published
## Install
Downloads
1,558
Keywords
Readme
@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