This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import config from './config.js';
|
||||
const username = process.env.KOILLECTION_USERNAME;
|
||||
const password = process.env.KOILLECTION_PASSWORD;
|
||||
|
||||
export async function createJWTToken() {
|
||||
try {
|
||||
const response = await fetch(`${config.baseUrl}/authentication_token`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ username, password }),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to obtain JWT token: ${response.status} - ${response.statusText}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
console.log(`JWT Token obtained: ${data.token}`);
|
||||
return data.token;
|
||||
} catch (error) {
|
||||
console.error(`Error obtaining JWT token:`, error);
|
||||
throw error; // Re-throw to be caught in other functions
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user