-
🏢 I’m currently working as a Freelancer
-
🌱 I’m currently learning React advance concepts and React Native
-
👯 I’m looking to collaborate on Lodgelink.net
-
👨💻 All of my projects are available at dinujaya.me
-
📝 I regularly write blog posts on blog.dinujaya.me
-
💬 Ask me about anything related to Information and Communication Technology
-
📫 How to reach me info.dinujaya@gmail.com
Simple code to use my bio data API ( https://api.dinujaya.me/ ) hosted in DigitalOcean VPS
const API_BASE_URL = "https://api.dinujaya.me";
// Function to sign in and obtain access token
const signIn = async (
username: string,
password: string
): Promise<string | null> => {
try {
const response = await axios.post<{ accessToken: string }>(
`${API_BASE_URL}/sign`,
{ username, password }
);
return response.data.accessToken;
} catch (error) {
console.error("Error signing in:", error);
return null;
}
};
// Function to get bio data using access token
const getBioData = async (accessToken: string): Promise<any> => {
try {
const response = await axios.get(`${API_BASE_URL}/`, {
headers: {
Authorization: `Bearer ${accessToken}`,
},
});
return response.data;
} catch (error) {
console.error("Error fetching bio data:", error);
return null;
}
};
useEffect(() => {
const getData = async () => {
// Example usage
const username = "your_username";
const password = "your_password";
// Sign in and obtain access token
const accessToken = await signIn(username, password);
if (accessToken) {
// Get bio data using access token
const bioData = await getBioData(accessToken);
console.log("Dinu's details: :", bioData);
} else {
console.log("Failed to obtain access token.");
}
};
getData();
}, []);