Added JWT token process

This commit is contained in:
2025-06-09 22:34:19 +02:00
parent 8f76832f69
commit 326bd1bd72
2 changed files with 45 additions and 7 deletions

View File

@@ -485,8 +485,23 @@ async function authenticateInstance() {
body: JSON.stringify({ email, password })
});
const responseData = await loginResponse.json();
console.log('Login response:', responseData);
// Check content type
const contentType = loginResponse.headers.get('content-type');
if (!contentType || !contentType.includes('application/json')) {
console.error('Unexpected content type:', contentType);
const text = await loginResponse.text();
console.error('Response text:', text);
throw new Error(`Server returned non-JSON response (${contentType}). Please check if the instance is properly configured.`);
}
let responseData;
try {
responseData = await loginResponse.json();
console.log('Login response:', responseData);
} catch (e) {
console.error('Failed to parse JSON response:', e);
throw new Error('Invalid JSON response from server');
}
if (!loginResponse.ok) {
throw new Error(responseData.message || 'Login failed');
@@ -514,8 +529,23 @@ async function authenticateInstance() {
})
});
const keyData = await keyResponse.json();
console.log('API key response:', keyData);
// Check content type for key response
const keyContentType = keyResponse.headers.get('content-type');
if (!keyContentType || !keyContentType.includes('application/json')) {
console.error('Unexpected content type for key response:', keyContentType);
const text = await keyResponse.text();
console.error('Key response text:', text);
throw new Error(`Server returned non-JSON response for API key (${keyContentType})`);
}
let keyData;
try {
keyData = await keyResponse.json();
console.log('API key response:', keyData);
} catch (e) {
console.error('Failed to parse JSON response for API key:', e);
throw new Error('Invalid JSON response from server for API key');
}
if (!keyResponse.ok) {
throw new Error(keyData.message || 'Failed to create API key');
@@ -536,8 +566,14 @@ async function authenticateInstance() {
body: JSON.stringify({ token: api_key })
});
const saveData = await saveResponse.json();
console.log('Save token response:', saveData);
let saveData;
try {
saveData = await saveResponse.json();
console.log('Save token response:', saveData);
} catch (e) {
console.error('Failed to parse JSON response for save token:', e);
throw new Error('Invalid JSON response from server for save token');
}
if (!saveResponse.ok) {
throw new Error(saveData.message || 'Failed to save token');