Add form login support to API client

This commit is contained in:
Alexa Amundson
2025-11-16 01:49:49 -06:00
parent b2f933762a
commit 88028375d1

View File

@@ -79,14 +79,26 @@ class ApiClient {
*/ */
async request(method, endpoint, data = null, options = {}) { async request(method, endpoint, data = null, options = {}) {
const url = `${this.baseUrl}${endpoint}`; const url = `${this.baseUrl}${endpoint}`;
const config = { const {
method, includeAuth = true,
headers: this.getHeaders(options.includeAuth !== false), headers: customHeaders = {},
...options, rawBody = false,
...fetchOptions
} = options;
const headers = {
...this.getHeaders(includeAuth),
...customHeaders,
}; };
if (data) { const config = {
config.body = JSON.stringify(data); method,
headers,
...fetchOptions,
};
if (data !== null && data !== undefined) {
config.body = rawBody ? data : JSON.stringify(data);
} }
try { try {
@@ -157,10 +169,17 @@ class ApiClient {
} }
async login(username, password) { async login(username, password) {
const response = await this.post('/api/auth/login', { const formData = new URLSearchParams();
username, formData.append('username', username);
password formData.append('password', password);
}, { includeAuth: false });
const response = await this.request('POST', '/api/auth/login', formData, {
includeAuth: false,
rawBody: true,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
if (response.access_token) { if (response.access_token) {
this.setToken(response.access_token); this.setToken(response.access_token);