mirror of
https://github.com/blackboxprogramming/BlackRoad-Operating-System.git
synced 2026-03-17 07:57:19 -05:00
Add form login support to API client
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user