Interlink Labs MDK – universal React/TS SDK
npm install @interlinklabs/test-mdk@interlinklabs/mdk library:
bash
npm install @interlinklabs/mdk
`
2. Import the Mdk SDK into your project from the corresponding file.
---
3. Using the SDK
$3
Integrate the SDK by using the Mdk component in your application.
`tsx
import React from "react";
import Mdk from "@interlinklabs/mdk";
const App = () => {
const handleSuccess = () => {
console.log("Login successful!");
};
const handleFailure = () => {
console.log("Login failed.");
};
return (
appid="your-app-id"
onSuccess={handleSuccess}
onFailure={handleFailure}
>
{({ open }) => }
);
};
export default App;
`
#### Mdk Properties:
- appid (string): Your application ID for identification.
- onSuccess (function): A callback function triggered upon successful login.
- onFailure (function): A callback function triggered upon login failure.
- children (function): Renders UI components with the { open } property to initiate the login process.
---
$3
#### 1. Mdk.getLoginId()
- Description: Retrieves the loginId from the JWT stored in cookies.
- Usage:
`tsx
const loginId = Mdk.getLoginId("your-app-id");
console.log("Login ID:", loginId);
`
#### 2. Mdk.getUserName()
- Description: Fetches the username associated with a given loginId.
- Usage:
`tsx
const username = await Mdk.getUserName("your-app-id");
console.log("Username:", username);
`
#### 3. Mdk.logOut()
- Description: Deletes the JWT token and logs out the user.
- Usage:
`tsx
Mdk.logOut("your-app-id");
console.log("Logged out!");
``