You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
747 B
35 lines
747 B
import { Buffer } from 'buffer';
|
|
|
|
const fecher = async(url: string, headerAuth: string) => {
|
|
return await fetch(url, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Authorization': headerAuth
|
|
}
|
|
})
|
|
}
|
|
|
|
|
|
|
|
export const useBasicAuth = async (username: string, password: string) => {
|
|
console.debug(username + " : " + password)
|
|
const headerAuth = 'Basic ' + Buffer.from(username+ ":"+ password).toString("base64");
|
|
let token = "";
|
|
try {
|
|
|
|
|
|
const response = await fecher("http://149.56.97.9:8080/login", headerAuth);
|
|
|
|
if (response.ok){
|
|
|
|
token = response.headers.get("Authorization") || "";
|
|
}
|
|
} catch (error) {
|
|
|
|
}
|
|
|
|
return {
|
|
token
|
|
}
|
|
|
|
} |